<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-99.9.9">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

<meta name="author" content="J Andres Gannon">
<meta name="dcterms.date" content="2023-04-11">

<title>Model Prep</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>


<script src="04_Model_Prep_files/libs/clipboard/clipboard.min.js"></script>
<script src="04_Model_Prep_files/libs/quarto-html/quarto.js"></script>
<script src="04_Model_Prep_files/libs/quarto-html/popper.min.js"></script>
<script src="04_Model_Prep_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="04_Model_Prep_files/libs/quarto-html/anchor.min.js"></script>
<link href="04_Model_Prep_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="04_Model_Prep_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="04_Model_Prep_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="04_Model_Prep_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="04_Model_Prep_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet">

<script src="04_Model_Prep_files/libs/htmlwidgets-1.6.2/htmlwidgets.js"></script>
<link href="04_Model_Prep_files/libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet">
<script src="04_Model_Prep_files/libs/datatables-binding-0.27/datatables.js"></script>
<script src="04_Model_Prep_files/libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<link href="04_Model_Prep_files/libs/dt-core-1.12.1/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="04_Model_Prep_files/libs/dt-core-1.12.1/css/jquery.dataTables.extra.css" rel="stylesheet">
<script src="04_Model_Prep_files/libs/dt-core-1.12.1/js/jquery.dataTables.min.js"></script>
<link href="04_Model_Prep_files/libs/crosstalk-1.2.0/css/crosstalk.min.css" rel="stylesheet">
<script src="04_Model_Prep_files/libs/crosstalk-1.2.0/js/crosstalk.min.js"></script>
<link href="04_Model_Prep_files/libs/nouislider-7.0.10/jquery.nouislider.min.css" rel="stylesheet">
<script src="04_Model_Prep_files/libs/nouislider-7.0.10/jquery.nouislider.min.js"></script>
<link href="04_Model_Prep_files/libs/selectize-0.12.0/selectize.bootstrap3.css" rel="stylesheet">
<script src="04_Model_Prep_files/libs/selectize-0.12.0/selectize.min.js"></script>


<link rel="stylesheet" href="styles.css">
</head>

<body>

<header id="title-block-header" class="quarto-title-block default page-columns page-full">
  <div class="quarto-title-banner page-columns page-full">
    <div class="quarto-title column-body">
      <div class="quarto-title-block"><div><h1 class="title">Model Prep</h1><button type="button" class="btn code-tools-button dropdown-toggle" id="quarto-code-tools-menu" data-bs-toggle="dropdown" aria-expanded="false"><i class="bi"></i> Code</button><ul class="dropdown-menu dropdown-menu-end" aria-labelelledby="quarto-code-tools-menu"><li><a id="quarto-show-all-code" class="dropdown-item" href="javascript:void(0)" role="button">Show All Code</a></li><li><a id="quarto-hide-all-code" class="dropdown-item" href="javascript:void(0)" role="button">Hide All Code</a></li><li><hr class="dropdown-divider"></li><li><a id="quarto-view-source" class="dropdown-item" href="javascript:void(0)" role="button">View Source</a></li></ul></div></div>
                      </div>
  </div>
    
  
  <div class="quarto-title-meta">

      <div>
      <div class="quarto-title-meta-heading">Author</div>
      <div class="quarto-title-meta-contents">
               <p>J Andres Gannon </p>
            </div>
    </div>
      
      <div>
      <div class="quarto-title-meta-heading">Published</div>
      <div class="quarto-title-meta-contents">
        <p class="date">April 11, 2023</p>
      </div>
    </div>
      
    </div>
    
  
  </header><div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
  <nav id="TOC" role="doc-toc">
    <h2 id="toc-title">Table of contents</h2>
   
  <ul>
  <li><a href="#set-up" id="toc-set-up" class="nav-link active" data-scroll-target="#set-up">Set up</a></li>
  <li><a href="#intervention-list" id="toc-intervention-list" class="nav-link" data-scroll-target="#intervention-list">Intervention list</a>
  <ul class="collapse">
  <li><a href="#clean" id="toc-clean" class="nav-link" data-scroll-target="#clean">Clean</a></li>
  <li><a href="#quick-checks" id="toc-quick-checks" class="nav-link" data-scroll-target="#quick-checks">Quick checks</a></li>
  </ul></li>
  <li><a href="#prep-variables" id="toc-prep-variables" class="nav-link" data-scroll-target="#prep-variables">Prep variables</a>
  <ul class="collapse">
  <li><a href="#actors" id="toc-actors" class="nav-link" data-scroll-target="#actors">Actors</a></li>
  </ul></li>
  <li><a href="#condense-uoa" id="toc-condense-uoa" class="nav-link" data-scroll-target="#condense-uoa">Condense UoA</a></li>
  <li><a href="#add-variables" id="toc-add-variables" class="nav-link" data-scroll-target="#add-variables">Add variables</a>
  <ul class="collapse">
  <li><a href="#public-approval" id="toc-public-approval" class="nav-link" data-scroll-target="#public-approval">Public approval</a></li>
  <li><a href="#casualties" id="toc-casualties" class="nav-link" data-scroll-target="#casualties">Casualties</a></li>
  <li><a href="#collateral-damage" id="toc-collateral-damage" class="nav-link" data-scroll-target="#collateral-damage">Collateral damage</a></li>
  </ul></li>
  <li><a href="#final-clean" id="toc-final-clean" class="nav-link" data-scroll-target="#final-clean">Final clean</a></li>
  <li><a href="#save" id="toc-save" class="nav-link" data-scroll-target="#save">Save</a></li>
  </ul>
</nav>
</div>
<main class="content quarto-banner-title-block" id="quarto-document-content">




<section id="set-up" class="level1">
<h1>Set up</h1>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-1_3c5eeb59842ba2b43015c8fa4aaf96c1">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(magrittr)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="intervention-list" class="level1">
<h1>Intervention list</h1>
<p>Start by loading the cleaned intervention list</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-2_d99fa35593c514c3275102b26177ca70">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"02a_interventions_newdata_dbpedia.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_name, wikidata_id,</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>                location_name, lat, lon,</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>                start_date, end_date, duration,</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>                belligerent_sideA, belligerent_sideB,</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"means_"</span>),</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"casualties_"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Merge with parent observations which gives us the current list of operations</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a>ops <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"03_interventions_newdata_childof_operations.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(<span class="sc">-</span>X) <span class="sc">%&gt;%</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(ops, df)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<section id="clean" class="level2">
<h2 class="anchored" data-anchor-id="clean">Clean</h2>
<p>Subset to just the US, and drop dyads that don’t involve the US</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-3_d9daf291cb0bc3798e43579559b33398">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>ally <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(wikidata_name, wikidata_id) <span class="sc">%&gt;%</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">participants =</span> dplyr<span class="sc">::</span><span class="fu">n_distinct</span>(belligerent_sideA)) <span class="sc">%&gt;%</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">participants =</span> participants<span class="dv">-1</span>)</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>ally <span class="sc">%&gt;%</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="datatables html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-38f94d3d28d10a88cee4" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-38f94d3d28d10a88cee4">{"x":{"filter":"none","vertical":false,"data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100","101","102","103","104","105","106","107","108","109","110","111","112","113","114","115","116","117","118","119","120","121","122","123","124","125","126","127","128","129","130","131","132","133","134","135","136","137","138","139","140","141","142","143","144","145","146","147","148","149","150","151","152","153","154","155","156","157","158","159","160","161","162","163","164","165","166","167","168","169","170","171","172","173","174","175","176","177","178","179","180","181","182","183","184","185","186","187","188","189","190","191","192","193","194","195","196","197","198","199","200","201","202","203","204","205","206","207","208","209","210","211","212","213","214","215","216","217","218","219","220","221","222","223","224","225","226","227","228","229","230","231","232","233","234","235","236","237","238","239","240","241","242","243","244","245","246","247","248","249","250","251","252","253","254","255","256","257","258","259","260","261","262","263","264","265","266","267","268","269","270","271","272","273","274","275","276","277","278","279","280","281","282","283","284","285","286","287","288","289","290","291","292","293","294","295","296","297","298","299","300","301","302","303","304","305"],["1989 Philippine coup attempt","1993 cruise missile strikes on Iraq","1999 F-117A shootdown","2001 Sayyd Alma Kalay airstrike","2001 uprising in Herat","2003 Mosul raid","2007 Helmand Province airstrikes","2008 Abu Kamal raid","2009 Baraawe raid","2009 Kunduz airstrike","2010 Sangin airstrike","2012 Kapisa airstrike","2013 raid on Barawe","2014 American raid in Libya","2016 Dabiq offensive","2016 Sirte offensive","2017 Baghdad–Damascus highway offensive","2017 Mosul airstrike","2017 Nangarhar airstrike","2017 Sangin airstrike","2017 Shayrat missile strike","2017 al-Jinah airstrike","2017 raid on Barii","2017 southern Syria offensive","2018 missile strikes against Syria","2020 Baghdad International Airport airstrike","Abyan conflict","Action of 18 March 2006","Action of 28 October 2007","Action of 3 June 2007","Al-Hasakah city offensive (June 2015)","Al-Hasakah offensive","Al-Hasakah offensive","Al-Hawl Offensive (2015)","Al-Karmah offensive (2015)","Al-Shaddadi offensive (2016)","Amiriyah shelter bombing","Anbar campaign (2015–16)","Attack on Ras Tanura","Azizabad airstrike","Baghar China airstrike","Baraki Barak airstrike","Barisha raid","Battle of 73 Easting","Battle of Ad-Dawrah","Battle of Al Faw (2003)","Battle of Al Mukalla (2016)","Battle of Al-Qa'im","Battle of Alasay","Battle of Baghdad","Battle of Baghdad (2003)","Battle of Baqubah","Battle of Barawala Kalay Valley","Battle of Bargal (2007)","Battle of Basra (2003)","Battle of Basra (2008)","Battle of Chora","Battle of Dahaneh","Battle of Debecka Pass","Battle of Do Ab","Battle of Garmsir","Battle of Haditha Dam","Battle of Haifa Street","Battle of Kamdesh","Battle of Khafji","Battle of Khaz Oruzgan","Battle of Košare","Battle of Kuwait International Airport","Battle of Najaf (2004)","Battle of Norfolk","Battle of Qurah and Umm al Maradim","Battle of Ramadi (2006)","Battle of Raqqa (2017)","Battle of Ras Kamboni","Battle of Samarra (2004)","Battle of Samawah (2003)","Battle of Sangin (2010)","Battle of Sarrin (June–July 2015)","Battle of Sarrin (March–April 2015)","Battle of Shok Valley","Battle of Tabqa Dam","Battle of Tal Afar (2005)","Battle of Tarinkot","Battle of Tora Bora","Battle of Turki","Battle of Wadi Al-Batin","Battle of al-Bab","Battle of the Palm Grove","Bombing of Iraq","Bombing of Kandahar (2001)","Chenagai airstrike","Cruise missile strikes on Iraq","Datta Khel airstrike","December 2018 airstrikes in Gandarshe","December 2019 United States airstrikes in Iraq and Syria","Deir ez-Zor offensive","Dhusamareb airstrike","Dobley airstrike","Dubrava Prison bombings and executions","East Aleppo offensive","Fall of Kabul","Fall of Kandahar","Fall of Mazar-i-Sharif","Fall of Sangin","February 2021 United States airstrike in Syria","First Battle of Fallujah","First and Second Battles of Kakarak","Ghazni offensive","Gora Prai airstrike","Granai airstrike","Grdelica train bombing","Hadramaut Insurgency","Haska Meyna wedding party airstrike","Hawija offensive (2017)","Hyderabad airstrike","Implementation Force","Iraq spring fighting of 2008","Ja'Din shootdown incident","January 1993 airstrikes on Iraq","June 2021 United States airstrike in Syria","Koriša bombing","Kosovo Force","Kunduz hospital airstrike","Laghman airstrikes","Lužane bus bombing","Manbij offensive","Mano Gai airstrike","May 2015 U.S. special forces raid in Syria","Miramshah airstrike","Mohmand Valley raid","Mosul offensive (2015)","Mosul offensive (2016)","NATO bombing of Albanian refugees near Gjakova","NATO bombing of Novi Sad","NATO bombing of the Radio Television of Serbia headquarters","Nangarhar Offensive (2016)","Night raid on Narang","Nineveh Plains offensive","Nineveh campaign","Niš cluster bombing","Northern Aleppo offensive","Northern Iraq offensive","Northern Raqqa offensive (May 2016)","Northern al-Bab offensive","November 2015 Sinjar offensive","November 2017 Somalia airstrike","Operation Able Rising Force","Operation Able Warrior","Operation Achilles","Operation Airborne Dragon","Operation Al Majid","Operation Alljah","Operation Anaconda","Operation Arbead II","Operation Ardennes","Operation Asbury Park","Operation Augurs of Prosperity","Operation Avalanche (Afghanistan)","Operation Badlands","Operation Bayonet Lightning","Operation Black Eagle","Operation Bull Run","Operation Bulldog Bite","Operation Bulldog Mammoth","Operation Champion Sword","Operation Cobra's Anger","Operation Commando Eagle","Operation Crescent Wind","Operation Dagger","Operation Defeat Al Qaeda in the North","Operation Deliberate Force","Operation Deny Flight","Operation Desert Scorpion (Iraq 2003)","Operation Desert Spring","Operation Desert Thrust","Operation Desert Thunder","Operation Dragon Fire East","Operation Dragon Strike","Operation Eagle Ares","Operation Eagle Fury","Operation Eagle's Summit","Operation Enduring Freedom – Philippines","Operation Forsythe Park","Operation Freedom's Sentinel","Operation Gaugamela","Operation Gothic Serpent","Operation Guardian Tiger IV","Operation Halmazag","Operation Hammer (Afghanistan)","Operation Hammer Down","Operation Harekate Yolo","Operation Harpoon (2002)","Operation Haven Denial","Operation Imposing Law","Operation Indian Ocean","Operation Infinite Reach","Operation Iron Hammer (Iraq 2003)","Operation Iron Hammer (Iraq 2005)","Operation Iron Justice","Operation Iron Saber","Operation Iron Triangle","Operation Ivy Blizzard","Operation Jacana","Operation Kaika","Operation Karez","Operation Larchwood 4","Operation Leyte Gulf","Operation Lion's Leap","Operation Maritime Guard","Operation Maritime Monitor","Operation Marlborough","Operation Marne Avalanche","Operation Marne Courageous","Operation Marne Torch","Operation Mawtini","Operation Medusa","Operation Mongoose (2003)","Operation Moshtarak","Operation Mountain Fury","Operation Mountain Resolve","Operation Mountain Thrust","Operation Mountain Viper","Operation Murfreesboro","Operation New Market","Operation Northern Watch","Operation Observant Compass","Operation Ocean Shield","Operation Oqab","Operation Panther Squeeze","Operation Panther's Claw","Operation Peninsula Strike","Operation Perth","Operation Phantom Linebacker","Operation Phantom Phoenix","Operation Phantom Strike","Operation Phantom Thunder","Operation Pickaxe-Handle","Operation Planet X","Operation Plymouth Rock","Operation Polar Tempest","Operation Provide Comfort","Operation Purple Haze","Operation Red Dawn","Operation Red Wings","Operation Rhino","Operation River Falcon","Operation Rock Avalanche","Operation Saber Guardian","Operation Sayeed","Operation Scorpion","Operation Secure Tomorrow","Operation Senior Surprise","Operation Septentrion","Operation Sharp Guard","Operation Shurta Nasir","Operation Sky Monitor","Operation Southern Focus","Operation Spear","Operation Squeeze Play","Operation Steel Curtain","Operation Strike of the Sword","Operation Swarmer","Operation Tar Heels","Operation Tidal Wave II","Operation Tiger Hammer","Operation Together Forward","Operation Unified Protector","Operation United Shield","Operation Uphold Democracy","Operation Valiant Guardian","Operation Valiant Strike","Operation Vigilant Sentinel","Operation Vigilant Warrior","Operation Viking Hammer","Operation Warrior Sweep","Operation Warrior's Rage","Operation Whalers","Oruzgan police station attack of January 2002","Package Q Strike","Palmyra offensive (December 2016)","Raid on Al Hathla","Raid on Hazar Qadam","Raid on Khataba","Raid on Kunar","Raid on Yakla","Rescue of Jessica Buchanan and Poul Hagen Thisted","SY Quest incident","Salahuddin campaign","Samurra Air Battle","Second Battle of Fallujah","Second Battle of Habbaniyah","September 2012 raid on Camp Bastion","September 2016 Deir ez-Zor air raid","Shabwah Governorate offensive","Shah Wali Kot Offensive","Shrawangai Nazarkhel airstrike","Siege of Kunduz","Siege of Musa Qala","Siege of Sadr City","Tishrin Dam offensive","U.S. raid on the Iranian Liaison Office in Arbil","United States bombing of the Chinese embassy in Belgrade","Uruzgan helicopter attack","Wech Baghtu wedding party airstrike","Western Nineveh offensive (2017)"],["Q4585384","Q5189962","Q335259","Q4599065","Q3152953","Q65074171","Q4608594","Q553332","Q10751263","Q1848486","Q7418013","Q4625940","Q17000965","Q23022941","Q27185813","Q24467647","Q29991963","Q29524697","Q29385187","Q30323833","Q29197866","Q28983702","Q30625807","Q28162889","Q51844684","Q80754846","Q32634886","Q2984712","Q4677332","Q4677356","Q20241081","Q19428973","Q20050670","Q21405560","Q19864219","Q22894201","Q2071090","Q22935666","Q28162756","Q2909596","Q4841775","Q4858273","Q72587856","Q1402530","Q4870215","Q1930510","Q23935847","Q1975663","Q385546","Q97304250","Q1804983","Q2237337","Q24905428","Q4870424","Q2585300","Q2888122","Q1485258","Q2888379","Q4870854","Q4870881","Q4871080","Q40889886","Q4871175","Q2664174","Q718770","Q4871421","Q3303959","Q19428991","Q2889462","Q3636553","Q4872147","Q2889747","Q30140821","Q4872168","Q4087318","Q4872256","Q4872292","Q20715216","Q19691931","Q4872371","Q29258911","Q972831","Q4872509","Q2237280","Q4872608","Q3636251","Q27915277","Q4872982","Q1327861","Q4871376","Q5091023","Q1781133","Q5227745","Q60765736","Q26847124","Q39899474","Q1328419","Q5286642","Q16836125","Q28846183","Q5432157","Q2888881","Q2889318","Q30686667","Q105707091","Q1537159","Q5454117","Q56085424","Q5584353","Q1136783","Q5598537","Q30682487","Q5252012","Q40532579","Q5953962","Q313577","Q6067932","Q60756557","Q105773263","Q107504334","Q2813755","Q159470","Q21057198","Q6472107","Q6706905","Q23701421","Q6751071","Q20860131","Q12327344","Q60770016","Q20647259","Q23540783","Q499623","Q4594928","Q4475947","Q23039091","Q6965344","Q21814411","Q7038210","Q4093050","Q25242026","Q17984373","Q24255637","Q27630575","Q21472342","Q60755056","Q7096724","Q7096725","Q1616794","Q7096734","Q7096735","Q7096739","Q1476042","Q7096757","Q7096760","Q7096764","Q3354646","Q7096775","Q7096780","Q7096794","Q3354655","Q11798527","Q7096856","Q7096859","Q7096884","Q1128855","Q7096918","Q7096941","Q7096953","Q7096967","Q160774","Q567343","Q7096982","Q7096978","Q7096979","Q3354687","Q7097002","Q2026053","Q7097017","Q7097022","Q3354694","Q2631285","Q7097057","Q21296923","Q7097069","Q3428977","Q7097106","Q1234017","Q3030335","Q30589255","Q1511923","Q2396979","Q7097122","Q1747422","Q18128999","Q837887","Q7097172","Q7097173","Q7097175","Q7097177","Q7097176","Q7097180","Q3354735","Q3354740","Q1518797","Q23043314","Q7097226","Q7097238","Q971510","Q321054","Q7097269","Q7097270","Q16931346","Q2026187","Q16932796","Q1763044","Q65076683","Q843588","Q909414","Q7097302","Q609978","Q5473413","Q7097303","Q7097325","Q2026233","Q65066391","Q2001981","Q2026247","Q7097371","Q3354803","Q4335239","Q4744313","Q7097388","Q2026267","Q1697088","Q2026272","Q7097394","Q7097399","Q2026278","Q7097403","Q2281470","Q7097429","Q3780506","Q3354826","Q3417667","Q7097465","Q2026322","Q7097481","Q7097502","Q7097510","Q7097528","Q85790978","Q3354840","Q472398","Q7097544","Q1000306","Q2739563","Q7097569","Q7097575","Q642100","Q2549377","Q477040","Q7097613","Q22907504","Q7097639","Q7097646","Q3269455","Q16250538","Q2026486","Q7097682","Q7097684","Q7097689","Q1838811","Q1678616","Q7097704","Q7097703","Q7097713","Q7105180","Q7122885","Q27988133","Q30089867","Q5687552","Q6400879","Q6444187","Q28716912","Q7315022","Q647100","Q19574810","Q28162754","Q1330136","Q24083362","Q15276208","Q26945162","Q23022688","Q2083522","Q7503440","Q3485911","Q7510253","Q3486016","Q21860041","Q7863480","Q2418042","Q8207886","Q7979006","Q30014900"],[1,0,0,0,3,0,0,0,0,1,1,0,0,0,2,3,4,0,0,0,0,0,1,3,2,0,5,0,0,0,6,8,4,4,3,2,0,5,1,0,0,0,0,1,2,3,4,0,3,3,1,1,0,1,3,4,0,2,1,2,3,0,1,2,6,2,4,0,1,1,1,1,1,2,1,0,3,5,6,1,6,1,1,3,0,1,3,1,1,1,0,0,0,1,0,9,0,0,1,4,1,3,1,1,0,0,2,1,0,0,0,4,0,3,0,32,3,1,2,0,1,0,0,1,1,8,0,1,0,1,7,7,1,0,1,2,1,5,1,0,2,1,1,2,4,0,1,0,6,0,1,1,10,0,1,1,1,1,0,1,3,1,1,0,1,2,1,1,1,1,1,1,0,0,0,11,1,2,1,1,7,2,1,39,1,5,1,3,5,1,0,1,1,4,2,1,1,1,1,1,0,1,3,1,4,2,1,3,0,0,1,1,0,1,1,5,2,6,6,0,7,1,1,1,2,4,0,3,1,4,0,1,3,3,1,4,6,1,2,1,8,1,0,0,0,1,1,1,1,1,3,0,0,0,1,0,0,1,1,1,2,1,0,0,0,2,17,0,2,1,2,1,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,10,0,2,0,2,3,2,2,0,1,5,2,1,0,0,0,0,2]],"container":"<table class=\"display\">\n  <thead>\n    <tr>\n      <th> <\/th>\n      <th>wikidata_name<\/th>\n      <th>wikidata_id<\/th>\n      <th>participants<\/th>\n    <\/tr>\n  <\/thead>\n<\/table>","options":{"columnDefs":[{"className":"dt-right","targets":3},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false}},"evals":[],"jsHooks":[]}</script>
</div>
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, ally) <span class="sc">%&gt;%</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">belligerent_sideA =</span> <span class="st">"United States"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">ccode1 =</span> <span class="fu">as.numeric</span>(<span class="dv">2</span>),</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>                <span class="at">cname1 =</span> <span class="st">"USA"</span>,</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>                <span class="at">qcode1 =</span> <span class="st">"Q30"</span>,</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>                <span class="at">multilateral1 =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(participants <span class="sc">&gt;</span> <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">belligerent1 =</span> belligerent_sideA,</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>                <span class="at">belligerent2 =</span> belligerent_sideB,</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>                <span class="at">allycount1 =</span> participants) <span class="sc">%&gt;%</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="quick-checks" class="level2">
<h2 class="anchored" data-anchor-id="quick-checks">Quick checks</h2>
<p>Intervention that span more than a year. Make a temporary variable for start year</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-4_3c9929c686b8e3bc49fe05971f99d8fc">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%&gt;%</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_name, start_date, end_date) <span class="sc">%&gt;%</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">year_start =</span> <span class="fu">format</span>(<span class="fu">as.Date</span>(start_date, <span class="at">format=</span><span class="st">"%Y-%m-%d"</span>),<span class="st">"%Y"</span>),</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>                <span class="at">year_end =</span> <span class="fu">format</span>(<span class="fu">as.Date</span>(end_date, <span class="at">format=</span><span class="st">"%Y-%m-%d"</span>),<span class="st">"%Y"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">filter</span>(year_end <span class="sc">&gt;</span> year_start) <span class="sc">%&gt;%</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(<span class="sc">!</span>dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"year_"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>() <span class="sc">%&gt;%</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>(<span class="at">filter =</span> <span class="st">"top"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="datatables html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-403a3613ac71831916e5" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-403a3613ac71831916e5">{"x":{"filter":"top","vertical":false,"filterHTML":"<tr>\n  <td><\/td>\n  <td data-type=\"character\" style=\"vertical-align: top;\">\n    <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n      <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n      <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\"><\/span>\n    <\/div>\n  <\/td>\n  <td data-type=\"character\" style=\"vertical-align: top;\">\n    <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n      <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n      <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\"><\/span>\n    <\/div>\n  <\/td>\n  <td data-type=\"character\" style=\"vertical-align: top;\">\n    <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n      <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n      <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\"><\/span>\n    <\/div>\n  <\/td>\n<\/tr>","data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28"],["Operation Uphold Democracy","2017 southern Syria offensive","Deir ez-Zor offensive","Battle of al-Bab","Operation Indian Ocean","Operation Vigilant Sentinel","Operation Desert Spring","Operation Provide Comfort","Operation Southern Focus","Anbar campaign (2015–16)","Operation Al Majid","Battle of Baghdad","Second Battle of Habbaniyah","Operation Iron Hammer (Iraq 2005)","Operation Marlborough","Operation Phantom Strike","Siege of Sadr City","Operation Observant Compass","Operation Enduring Freedom – Philippines","Battle of Sangin (2010)","Operation Mountain Fury","Operation Anaconda","Operation Freedom's Sentinel","Abyan conflict","Hadramaut Insurgency","Shabwah Governorate offensive","Implementation Force","Operation Deny Flight"],["1994-09-19","2016-12-29","2017-09-08","2016-11-06","2014-08-16","1995-12-01","1998-12-31","1991-03-01","2002-06-01","2015-07-13","2006-09-01","2006-02-22","2006-08-17","2005-11-30","2005-07-23","2007-08-15","2004-04-04","2011-10-12","2002-01-15","2010-07-01","2006-09-16","2002-03-01","2015-01-01","2016-02-22","2016-04-26","2014-03-17","1995-01-01","1993-04-12"],["1995-03-31","2017-05-30","2018-08-04","2017-02-23","2015-05-23","1997-02-17","2003-03-18","1996-12-31","2003-03-17","2016-06-30","2007-02-01","2008-05-11","2007-02-14","2006-01-03","2007-07-23","2008-01-01","2008-05-11","2017-09-01","2015-02-24","2011-05-01","2007-01-15","2003-03-18","2021-08-30","2018-08-19","2018-04-29","2016-12-03","1996-01-01","1995-12-20"]],"container":"<table class=\"display\">\n  <thead>\n    <tr>\n      <th> <\/th>\n      <th>wikidata_name<\/th>\n      <th>start_date<\/th>\n      <th>end_date<\/th>\n    <\/tr>\n  <\/thead>\n<\/table>","options":{"columnDefs":[{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"orderCellsTop":true}},"evals":[],"jsHooks":[]}</script>
</div>
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">year =</span> <span class="fu">as.numeric</span>(<span class="fu">format</span>(<span class="fu">as.Date</span>(start_date, <span class="at">format=</span><span class="st">"%Y-%m-%d"</span>),<span class="st">"%Y"</span>)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
</section>
<section id="prep-variables" class="level1">
<h1>Prep variables</h1>
<section id="actors" class="level2">
<h2 class="anchored" data-anchor-id="actors">Actors</h2>
<p>Get ccode for state actors</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-5_b0a9d1ac813f850ae84f44724b91e25f">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>qcodes <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"belligerent_list.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">filter</span>(<span class="fu">is.na</span>(ccode_wrong)) <span class="sc">%&gt;%</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent, ccode, cname, Qcode) <span class="sc">%&gt;%</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">belligerent2 =</span> belligerent,</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>                <span class="at">ccode2 =</span> ccode,</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>                <span class="at">cname2 =</span> cname,</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>                <span class="at">qcode2 =</span> Qcode)</span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, qcodes) <span class="sc">%&gt;%</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_nonstate =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(<span class="fu">is.na</span>(ccode2), <span class="dv">1</span>, <span class="dv">0</span>))</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%&gt;%</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent2, ccode2, cname2) <span class="sc">%&gt;%</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>() <span class="sc">%&gt;%</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">arrange</span>(ccode2) <span class="sc">%&gt;%</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>(<span class="at">filter =</span> <span class="st">"top"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="datatables html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-66911613862c1a9fd3a5" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-66911613862c1a9fd3a5">{"x":{"filter":"top","vertical":false,"filterHTML":"<tr>\n  <td><\/td>\n  <td data-type=\"character\" style=\"vertical-align: top;\">\n    <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n      <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n      <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\"><\/span>\n    <\/div>\n  <\/td>\n  <td data-type=\"integer\" style=\"vertical-align: top;\">\n    <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n      <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n      <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\"><\/span>\n    <\/div>\n    <div style=\"display: none;position: absolute;width: 200px;opacity: 1\">\n      <div data-min=\"41\" data-max=\"710\"><\/div>\n      <span style=\"float: left;\"><\/span>\n      <span style=\"float: right;\"><\/span>\n    <\/div>\n  <\/td>\n  <td data-type=\"character\" style=\"vertical-align: top;\">\n    <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n      <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n      <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\"><\/span>\n    <\/div>\n  <\/td>\n<\/tr>","data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100","101","102","103","104","105","106","107","108","109","110","111","112","113","114","115","116","117","118","119","120","121"],["Haiti","FR Yugoslavia","Yugoslavia","Republika Srpska","Russia","Ukraine","Belarus","Libyan Arab Jamahiriya","Sudan","Iran","Islamic Revolutionary Guard Corps","Iranian Revolutionary Guards","Quds Force","Iraq","Iraqi Republic","Republic of Iraq","Saddam Hussein and personal bodyguards","Pre-occupation Iraqi armed forces","Ba'athist Syrian Government","Syria","Syrian Arab Republic","Syrian Army","Islamic Emirate of Afghanistan","Afghanistan","China","Reform the Armed Forces Movement","National Revolutionary Front for the Liberation of Haiti","al-Qaeda","Islamic State of Iraq and the Levant","Islamic State","Guardians of Religion Organization","CJTF-OIR","ISIL","Qasem Soleimani","Kata'ib Hezbollah","Kata'ib Sayyid al-Shuhada","SNA",null,"Al-Shabaab","Harkat-ul-Mujahideen","Lashkar-e-Taiba","Ansar al-Sharia - Libya","ISIL/ISIS","Ba'ath Party Loyalists","Iraqi Insurgency","Iraqi insurgency","Ansar al-Islam","Islamic Kurdistan","Islamic State of Iraq","Al-Qaeda in Iraq","Islamic state of Iraq","Other Iraqi insurgents","Mahdi Army","Mujahideen Shura Council","Jama'at al-Tawhid wal-Jihad","Other Insurgents","Iraqi insurgents","Iraqi Insurgents","Ba-athists","Other Sunni insurgents","Special Groups","Fadhila militia","al-Qaeda in Iraq","Ansar al-Sunna","Other insurgents","Mahdi Amry","Asa'ib Ahl al-Haq","Promised Day Brigade","Badr Brigades","Rogue elements among the Iraqi security forces","Soldiers of Heaven","Shia tribes","other militias","Tanzim Qaidat al-Jihad fi Bilad al-Rafidayn","Other Iraqi Insurgents","other Iraqi insurgents","al-Mahdi Army","Islamic Army of Iraq","1920 Revolution Brigade","Ba'athists","Army of Mohammed","Army of the Mujahedeen","Secret Islamic Army of Iraq","Fadhila Militia","Thar Allah","al-Shabaab","Islamic Courts Union","Pro-Islamist militias","Foreign fighters","Lord's Resistance Army","Somali pirates","Abu Sayyaf","BIFF","Maute Group","Jemaah Islamiyah","Taliban","Islamic State of Iraq and the Levant - Khorasan Province","Taliban insurgents","Taliban insurgency","Hezb-e-Islami Gulbuddin","Islamic Jihad Union","IMU","TNSM","ETIM","Insurgents","Al-Qaeda","Quetta Shura","other allied groups","Local anti-coalition militants","ISIL-KP","Islamic Movement of Uzbekistan","Anti-Coalition/Government forces","Al Qaeda","Hezb-e Islami Gulbuddin","Suspected Taliban insurgents","Other Anti-Afghan government forces","Hafiz Gul Bahadur","Islamic State of Iraq and the Levant - Yemen Province","Local militias","AQAP","al-Qaeda in the Arabian Peninsula"],[41,345,345,346,365,369,370,620,625,630,630,630,630,645,645,645,645,645,652,652,652,652,700,700,710,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],["Haiti","Yugoslavia","Yugoslavia","Bosnia &amp; Herzegovina","Russia","Ukraine","Belarus","Libya","Sudan","Iran","Iran","Iran","Iran","Iraq","Iraq","Iraq","Iraq","Iraq","Syria","Syria","Syria","Syria","Afghanistan","Afghanistan","China","",null,"",null,"","","","","","","","","","","","",null,"","",null,null,"","",null,null,null,null,"","","","",null,null,"","","","",null,"","",null,"","","",null,"","","","",null,null,"",null,"","","","",null,"","","","","","","","","","","","","",null,"","","","","","","","","","","","","",null,"","","","",null,"","","","",""]],"container":"<table class=\"display\">\n  <thead>\n    <tr>\n      <th> <\/th>\n      <th>belligerent2<\/th>\n      <th>ccode2<\/th>\n      <th>cname2<\/th>\n    <\/tr>\n  <\/thead>\n<\/table>","options":{"columnDefs":[{"className":"dt-right","targets":2},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"orderCellsTop":true}},"evals":[],"jsHooks":[]}</script>
</div>
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co"># New list of sideB non-state actor info</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>sideb_nonstate <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"nonstate_actors.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">sideB_nonstate_major =</span> X) <span class="sc">%&gt;%</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent2, qcode2, sideB_nonstate_major)</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, sideb_nonstate)</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Make all state actors 0 for nonstate major</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_nonstate_major =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(sideB_nonstate_major), <span class="dv">0</span>, sideB_nonstate_major))</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%&gt;%</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent2, cname2, sideB_nonstate, sideB_nonstate_major) <span class="sc">%&gt;%</span></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="datatables html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-c1d385c4f91518dff155" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-c1d385c4f91518dff155">{"x":{"filter":"none","vertical":false,"data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100","101","102","103","104","105","106","107","108","109","110","111","112","113","114","115","116","117","118","119","120","121","122","123","124","125","126","127","128","129","130","131","132","133","134","135","136","137","138","139","140","141","142","143","144","145","146","147","148","149","150","151","152","153","154","155","156","157","158","159","160","161","162","163","164","165","166","167","168","169","170","171","172","173","174","175","176","177","178","179","180","181","182","183","184","185","186","187","188","189","190","191","192","193","194","195","196","197","198","199","200","201","202","203","204","205","206","207","208","209","210","211","212","213","214","215","216","217","218","219","220","221","222","223","224","225","226","227","228","229","230","231","232","233","234","235","236","237","238","239","240","241","242","243","244","245","246","247","248","249","250","251","252","253","254","255","256","257","258","259","260","261","262","263","264","265","266","267","268","269","270","271","272","273","274","275","276","277","278","279","280","281","282","283","284","285","286","287","288","289","290","291","292","293","294","295","296","297","298","299","300","301","302","303","304","305","306","307","308","309","310","311","312","313","314","315","316","317","318","319","320","321","322","323","324","325","326","327","328","329","330","331","332","333","334","335","336","337","338","339","340","341","342","343","344","345","346","347","348","349","350","351","352","353","354","355","356","357","358","359","360","361","362","363","364","365","366","367","368","369","370","371","372","373","374","375","376","377","378","379","380","381","382","383","384","385","386","387","388","389","390","391","392","393","394","395","396","397","398","399","400","401","402","403","404","405","406","407","408","409","410","411","412","413","414","415","416","417","418","419","420","421","422","423","424","425","426","427","428","429","430","431","432","433","434","435","436","437","438","439","440","441","442","443","444","445","446","447","448"],["Reform the Armed Forces Movement","Haiti","National Revolutionary Front for the Liberation of Haiti","al-Qaeda","Ba'athist Syrian Government","Syria","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State","Guardians of Religion Organization","Syrian Arab Republic","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Syrian Army","Islamic State of Iraq and the Levant","Syrian Arab Republic","Russia","Iran","Islamic State of Iraq and the Levant","Syria","Russia","Iran","CJTF-OIR","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","ISIL","Islamic State","Islamic State","Islamic State of Iraq and the Levant","Islamic State","Islamic State","Islamic Revolutionary Guard Corps","Qasem Soleimani","Kata'ib Hezbollah","Kata'ib Hezbollah","Kata'ib Sayyid al-Shuhada","Kata'ib Hezbollah","Kata'ib Sayyid al-Shuhada","SNA",null,"al-Qaeda","Al-Shabaab","Al-Shabaab","Iraq","Iraq","Iraq","Iraq","Iraqi Republic","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Belarus","Russia","Ukraine","Syria","Iraq","Republic of Iraq","Belarus","Ukraine","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Libyan Arab Jamahiriya","Islamic State of Iraq and the Levant","al-Qaeda","Sudan","Harkat-ul-Mujahideen","Lashkar-e-Taiba","al-Qaeda","Sudan","Harkat-ul-Mujahideen","Lashkar-e-Taiba","Iranian Revolutionary Guards","Ansar al-Sharia - Libya","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Islamic State","Islamic State","Islamic State","ISIL/ISIS","Islamic State of Iraq and the Levant","Islamic State of Iraq and the Levant","Ba'ath Party Loyalists","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraqi Insurgency","Iraqi insurgency","Ansar al-Islam","Islamic Kurdistan","Iraq","Islamic State of Iraq","Al-Qaeda in Iraq","Islamic state of Iraq","Other Iraqi insurgents","Mahdi Army","Mahdi Army","Mujahideen Shura Council","Islamic State of Iraq","Jama'at al-Tawhid wal-Jihad","Ba'ath Party Loyalists","Al-Qaeda in Iraq","Other Insurgents","Iraqi Insurgency","Islamic state of Iraq","Islamic State of Iraq","Islamic state of Iraq","Other Iraqi insurgents","Iraqi insurgents","Iraqi Insurgents","Mujahideen Shura Council","Al-Qaeda in Iraq","Other Iraqi insurgents","Iraqi insurgency","Jama'at al-Tawhid wal-Jihad","Ba-athists","Other Sunni insurgents","Mahdi Army","Mahdi Army","Special Groups","Fadhila militia","Iraqi insurgency","al-Qaeda in Iraq","Ba'ath Party Loyalists","Ansar al-Sunna","Other Insurgents","al-Qaeda in Iraq","Other insurgents","Al-Qaeda in Iraq","Islamic State of Iraq","Mahdi Amry","Asa'ib Ahl al-Haq","Kata'ib Hezbollah","Promised Day Brigade","Badr Brigades","Rogue elements among the Iraqi security forces","Soldiers of Heaven","Shia tribes","other militias","Al-Qaeda in Iraq","Iraqi Insurgency","Iraqi Insurgency","Iraqi Insurgency","Iraqi Insurgency","Iraqi Insurgency","Iraqi insurgency","Mahdi Army","Mahdi Army","Iraq","Iraqi insurgents","Tanzim Qaidat al-Jihad fi Bilad al-Rafidayn","Iraqi insurgents",null,"Iraqi insurgency","Iraqi insurgency","Islamic state of Iraq","Other Iraqi Insurgents","Mujahideen Shura Council","Other Iraqi insurgents","Iraqi insurgency","Iraqi insurgency","Iraqi insurgency","Iraqi insurgency","Mahdi Army","Mahdi Army","al-Qaeda in Iraq","Iraqi insurgency","Mujahideen Shura Council","Al-Qaeda in Iraq","Iraqi Insurgency","Mahdi Army","Mahdi Army","Al-Qaeda in Iraq","Iraqi insurgency","Iraqi insurgency","Islamic state of Iraq","Iraqi insurgents","Iraqi insurgency","Iraqi Insurgents","Syria","Iraqi Insurgency","Islamic State of Iraq","Other Iraqi Insurgents","Islamic State of Iraq","Other Iraqi Insurgents","Islamic State of Iraq","Mahdi Army","Mahdi Army","Other Iraqi insurgents","Iraqi insurgency","Islamic state of Iraq","Other Iraqi insurgents","Islamic State of Iraq","Mahdi Army","Mahdi Army","Other Iraqi insurgents","Islamic state of Iraq","other Iraqi insurgents","Islamic state of Iraq","Other Iraqi insurgents","Islamic State of Iraq","other Iraqi insurgents","Iraqi insurgency","Iraqi insurgency","Iraqi insurgency","Saddam Hussein and personal bodyguards","Iraqi insurgency","Islamic state of Iraq","other Iraqi insurgents","Mujahideen Shura Council","Al-Qaeda in Iraq","other Iraqi insurgents","Islamic State of Iraq","Al-Qaeda in Iraq","al-Mahdi Army","Iraqi insurgents","Iraqi insurgency","Al-Qaeda in Iraq","Islamic Army of Iraq","Ansar al-Sunna","1920 Revolution Brigade","Ba'athists","Army of Mohammed","Army of the Mujahedeen","Secret Islamic Army of Iraq","Mahdi Army","Mahdi Army","Special Groups","Fadhila Militia","Thar Allah","Mahdi Army","Mahdi Army","Pre-occupation Iraqi armed forces","Islamic State of Iraq","Other Iraqi Insurgents","Islamic State of Iraq and the Levant","Islamic State","Islamic State of Iraq and the Levant","al-Qaeda","al-Shabaab","Al-Shabaab",null,null,null,"Al-Shabaab","Al-Shabaab","Islamic Courts Union","Islamic Courts Union","Pro-Islamist militias","Foreign fighters","al-Qaeda","al-Shabaab","Lord's Resistance Army",null,null,"Somali pirates","Abu Sayyaf","BIFF","Maute Group","Jemaah Islamiyah",null,"Islamic Emirate of Afghanistan","Taliban","Taliban","Taliban","Taliban","Islamic State of Iraq and the Levant - Khorasan Province","Taliban","Taliban","Taliban","Taliban insurgents",null,"Taliban insurgents","Taliban insurgents","Taliban insurgency","Taliban","Hezb-e-Islami Gulbuddin","Taliban","al-Qaeda","Taliban insurgents","Taliban insurgents","Islamic Jihad Union","Islamic Emirate of Afghanistan","al-Qaeda","Islamic Emirate of Afghanistan","Taliban","al-Qaeda","IMU","TNSM","ETIM","Foreign fighters","Taliban insurgents","Taliban","Taliban","Insurgents","Taliban","Taliban","Taliban insurgents","Taliban insurgents","Taliban insurgents","Taliban insurgents","Al-Qaeda","Taliban insurgents","Taliban","Taliban","Taliban insurgents","Taliban","Taliban insurgents","Taliban insurgents","Taliban insurgents","Taliban","Quetta Shura","Al-Qaeda","Taliban","al-Qaeda","Taliban insurgents","al-Qaeda","Taliban insurgents","Taliban insurgents","Taliban","Taliban insurgents","al-Qaeda","other allied groups","Local anti-coalition militants","Taliban insurgents","Afghanistan","ISIL-KP","Taliban","Taliban insurgents","al-Qaeda","Islamic Movement of Uzbekistan","Taliban","Anti-Coalition/Government forces","Taliban insurgents","Taliban insurgents","Islamic Emirate of Afghanistan","Taliban","Taliban insurgents","Quds Force","Taliban insurgents",null,"Taliban insurgents","al-Qaeda","Taliban","Al Qaeda","Taliban insurgents","al-Qaeda","Taliban insurgents","Hezb-e Islami Gulbuddin","Taliban","al-Qaeda","Taliban","Al Qaeda","Taliban","Taliban insurgents","Islamic Emirate of Afghanistan","Taliban","Taliban","Taliban insurgents","Taliban","Taliban","al-Qaeda","Taliban insurgents","Taliban","Al Qaeda","Taliban","Suspected Taliban insurgents","Taliban","Taliban","al-Qaeda","Other Anti-Afghan government forces","Islamic State of Iraq and the Levant","Taliban","Taliban","Islamic State of Iraq and the Levant","Taliban insurgents","Islamic Emirate of Afghanistan","Taliban","al-Qaeda","IMU","Islamic Emirate of Afghanistan","Taliban","Islamic Emirate of Afghanistan","al-Qaeda","Islamic Emirate of Afghanistan",null,"Taliban","Taliban","Taliban","al-Qaeda","Hafiz Gul Bahadur","Taliban","Islamic State","Taliban","Taliban","Al Qaeda","Al-Qaeda","Islamic State of Iraq and the Levant - Yemen Province","Local militias","AQAP","al-Qaeda in the Arabian Peninsula","al-Qaeda in the Arabian Peninsula","AQAP","AQAP","Republika Srpska","Republika Srpska","Republika Srpska","Republika Srpska",null,null,null,null,"Republika Srpska","Republika Srpska",null,null,"FR Yugoslavia","FR Yugoslavia","FR Yugoslavia","FR Yugoslavia","FR Yugoslavia","FR Yugoslavia","Yugoslavia","FR Yugoslavia",null,"China"],["","Haiti",null,"","Syria","Syria",null,null,"","","Syria",null,null,"Syria",null,"Syria","Russia","Iran",null,"Syria","Russia","Iran","",null,null,null,null,null,null,null,null,null,null,"","","",null,"","","Iran","","","","","","","","","","","","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Belarus","Russia","Ukraine","Syria","Iraq","Iraq","Belarus","Ukraine","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq","Libya",null,"","Sudan","","","","Sudan","","","Iran",null,null,null,null,"","","","",null,null,"","Iraq","Iraq","Iraq","Iraq","Iraq","Iraq",null,null,"","","Iraq",null,null,null,null,"","","",null,"","",null,"",null,null,null,null,null,null,null,"",null,null,null,"","","","","","","",null,null,"","","",null,"",null,null,null,"","","","",null,"","","",null,null,null,null,null,null,null,"","","Iraq",null,"",null,"",null,null,null,null,"",null,null,null,null,null,"","",null,null,"",null,null,"","",null,null,null,null,null,null,null,"Syria",null,null,null,null,null,null,"","",null,null,null,null,null,"","",null,null,null,null,null,null,null,null,null,null,"Iraq",null,null,null,"",null,null,null,null,"",null,null,null,null,"","","","","",null,"","","","","","","","Iraq",null,null,null,"",null,"","","","","","","","","","","","","","","","","","","","","","","","Afghanistan","","","","",null,"","","","","","","","","","","","","","","","Afghanistan","","Afghanistan","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","Afghanistan","","","","",null,"","","","","Afghanistan","","","Iran","","","","","","","","","","","","","","","","","Afghanistan","","","","","","","","","","","","","","",null,null,"","",null,"","Afghanistan","","","","Afghanistan","","Afghanistan","","Afghanistan","","","","","","","","","","","","","","","","","","","","Bosnia &amp; Herzegovina","Bosnia &amp; Herzegovina","Bosnia &amp; Herzegovina","Bosnia &amp; Herzegovina","","","","","Bosnia &amp; Herzegovina","Bosnia &amp; Herzegovina","","","Yugoslavia","Yugoslavia","Yugoslavia","Yugoslavia","Yugoslavia","Yugoslavia","Yugoslavia","Yugoslavia","","China"],[1,0,1,1,0,0,1,1,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0],[1,0,1,2,0,0,2,2,2,1,0,2,2,0,2,0,0,0,2,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,2,0,2,0,1,0,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,1,1,2,0,1,1,0,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0,0,0,1,1,1,1,0,2,2,2,1,1,1,1,2,1,1,2,0,1,2,2,2,1,1,1,1,2,1,1,1,1,0,1,1,2,1,1,2,1,1,0,2,0,2,2,1,2,2,2,2,1,1,0,0,2,1,1,1,1,1,1,1,1,0,1,2,1,0,1,1,2,1,1,1,1,1,1,1,1,1,2,1,1,2,1,1,1,2,1,1,2,1,1,1,0,1,2,1,2,1,2,1,1,1,1,2,1,2,1,1,1,2,1,2,1,2,1,1,1,1,0,1,2,1,1,2,1,2,2,1,1,1,2,1,1,1,1,1,1,1,1,1,2,1,0,1,1,0,2,1,2,2,2,2,1,1,0,0,0,1,1,1,1,0,0,2,1,1,0,0,0,2,1,1,1,0,0,2,2,2,2,2,2,2,2,2,0,2,2,2,2,1,2,2,2,2,1,0,2,0,2,2,2,1,1,0,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,0,2,2,2,2,2,2,0,2,2,0,2,2,0,2,0,2,2,2,2,2,2,2,1,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,0,2,2,2,0,2,0,2,0,0,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],"container":"<table class=\"display\">\n  <thead>\n    <tr>\n      <th> <\/th>\n      <th>belligerent2<\/th>\n      <th>cname2<\/th>\n      <th>sideB_nonstate<\/th>\n      <th>sideB_nonstate_major<\/th>\n    <\/tr>\n  <\/thead>\n<\/table>","options":{"columnDefs":[{"className":"dt-right","targets":[3,4]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p>Match parents to the main data, including the start date of the parent intervention and days into the parent intervention</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-6_3ede19ec10e8ac84a107f5056be613c0">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Pull all interventions so we have the start dates</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>df_parent <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"02a_interventions_newdata_dbpedia.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_id, start_date) <span class="sc">%&gt;%</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">parent_id =</span> <span class="st">"wikidata_id"</span>,</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a>                <span class="at">parent_start =</span> <span class="st">"start_date"</span>)</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, df_parent)</span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Calculate how many days into the parent intervention the child intervention occurred</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date =</span> <span class="fu">as.Date</span>(start_date, <span class="st">"%Y-%m-%d"</span>),</span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true" tabindex="-1"></a>                <span class="at">parent_start =</span> <span class="fu">as.Date</span>(parent_start, <span class="st">"%Y-%m-%d"</span>),</span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true" tabindex="-1"></a>                <span class="at">daysinto_parent =</span> <span class="fu">difftime</span>(start_date, parent_start, <span class="at">units =</span> <span class="fu">c</span>(<span class="st">"days"</span>)),</span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true" tabindex="-1"></a>                <span class="at">daysinto_parent =</span> <span class="fu">as.numeric</span>(daysinto_parent, <span class="at">units =</span> <span class="st">"days"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
</section>
<section id="condense-uoa" class="level1">
<h1>Condense UoA</h1>
<p>Collapse the data from intervention-dyad to intervention</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-7_ee5e9bc9f2911d01a5f29465cf17ee81">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"wikidata_"</span>), dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"parent_"</span>),</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"means_"</span>),</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a>                lat, lon, </span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a>                year, start_date, end_date, duration, parent_start, daysinto_parent,</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a>                allycount1, multilateral1,</span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"casualties_"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a>df_target <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_id,</span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a>                cname2, sideB_nonstate, sideB_nonstate_major) <span class="sc">%&gt;%</span></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(wikidata_id) <span class="sc">%&gt;%</span></span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">sideB_state_count =</span> dplyr<span class="sc">::</span><span class="fu">n_distinct</span>(cname2, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a>                   <span class="at">sideB_nonstate_all_count =</span> <span class="fu">sum</span>(sideB_nonstate, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a>                   <span class="at">sideB_nonstate_major_count =</span> <span class="fu">sum</span>(sideB_nonstate_major <span class="sc">==</span> <span class="dv">2</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a>                   <span class="at">sideB_nonstate_minor_count =</span> <span class="fu">sum</span>(sideB_nonstate_major <span class="sc">==</span> <span class="dv">1</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_state_ratio =</span> sideB_state_count<span class="sc">/</span>(sideB_state_count <span class="sc">+</span> sideB_nonstate_all_count)) <span class="sc">%&gt;%</span></span>
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_statenonstate_ordinal =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_ratio <span class="sc">==</span> <span class="dv">1</span>, </span>
<span id="cb10-20"><a href="#cb10-20" aria-hidden="true" tabindex="-1"></a>                                                              <span class="dv">0</span>, <span class="dv">0</span>),</span>
<span id="cb10-21"><a href="#cb10-21" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_statenonstate_ordinal =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_ratio <span class="sc">&lt;</span> <span class="dv">1</span> <span class="sc">&amp;</span> sideB_state_ratio <span class="sc">&gt;</span> <span class="dv">0</span>, </span>
<span id="cb10-22"><a href="#cb10-22" aria-hidden="true" tabindex="-1"></a>                                                              <span class="dv">1</span>, sideB_statenonstate_ordinal),</span>
<span id="cb10-23"><a href="#cb10-23" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_statenonstate_ordinal =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_ratio <span class="sc">==</span> <span class="dv">1</span>,</span>
<span id="cb10-24"><a href="#cb10-24" aria-hidden="true" tabindex="-1"></a>                                                              <span class="dv">2</span>, sideB_statenonstate_ordinal)) <span class="sc">%&gt;%</span></span>
<span id="cb10-25"><a href="#cb10-25" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_state_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb10-26"><a href="#cb10-26" aria-hidden="true" tabindex="-1"></a>                                                    <span class="dv">1</span>, <span class="dv">0</span>),</span>
<span id="cb10-27"><a href="#cb10-27" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_nonstate_all_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_nonstate_all_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb10-28"><a href="#cb10-28" aria-hidden="true" tabindex="-1"></a>                                                       <span class="dv">1</span>, <span class="dv">0</span>),</span>
<span id="cb10-29"><a href="#cb10-29" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_nonstate_major_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_nonstate_major_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb10-30"><a href="#cb10-30" aria-hidden="true" tabindex="-1"></a>                                                       <span class="dv">1</span>, <span class="dv">0</span>),</span>
<span id="cb10-31"><a href="#cb10-31" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_nonstate_minor_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_nonstate_minor_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb10-32"><a href="#cb10-32" aria-hidden="true" tabindex="-1"></a>                                                       <span class="dv">1</span>, <span class="dv">0</span>))</span>
<span id="cb10-33"><a href="#cb10-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-34"><a href="#cb10-34" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, df_target)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="add-variables" class="level1">
<h1>Add variables</h1>
<section id="public-approval" class="level2">
<h2 class="anchored" data-anchor-id="public-approval">Public approval</h2>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-8_50ad46038716f774c35469042ef47520">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>approval <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"approval.csv"</span>))</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Prep date variables</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>approval <span class="ot">&lt;-</span> approval <span class="sc">%&gt;%</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month),</span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>                <span class="at">approveL1 =</span> dplyr<span class="sc">::</span><span class="fu">lag</span>(approve),</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a>                <span class="at">disapproveL1 =</span> dplyr<span class="sc">::</span><span class="fu">lag</span>(disapprove))</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df_interv <span class="sc">%&gt;%</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date_month =</span> <span class="fu">substr</span>(start_date, <span class="at">start =</span> <span class="dv">1</span>, <span class="at">stop =</span> <span class="dv">7</span>))</span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Merge</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, approval)</span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Add Biden events</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df_interv <span class="sc">%&gt;%</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">presidentid =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(presidentid), <span class="st">"Joseph Biden"</span>, presidentid))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="casualties" class="level2">
<h2 class="anchored" data-anchor-id="casualties">Casualties</h2>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-9_8049291b1b4adc2709a5aa1729ae58d7">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>dates <span class="ot">&lt;-</span> approval <span class="sc">%&gt;%</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month)</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a>casualties_oef <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OEFMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"oef"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a>casualties_ofs <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OFSMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"ofs"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb12-19"><a href="#cb12-19" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-20"><a href="#cb12-20" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-21"><a href="#cb12-21" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb12-22"><a href="#cb12-22" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb12-23"><a href="#cb12-23" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-24"><a href="#cb12-24" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb12-25"><a href="#cb12-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-26"><a href="#cb12-26" aria-hidden="true" tabindex="-1"></a>casualties_oif <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OIFMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-27"><a href="#cb12-27" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"oif"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-28"><a href="#cb12-28" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-29"><a href="#cb12-29" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb12-30"><a href="#cb12-30" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-31"><a href="#cb12-31" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-32"><a href="#cb12-32" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb12-33"><a href="#cb12-33" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb12-34"><a href="#cb12-34" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-35"><a href="#cb12-35" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb12-36"><a href="#cb12-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-37"><a href="#cb12-37" aria-hidden="true" tabindex="-1"></a>casualties_oir <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OIRMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-38"><a href="#cb12-38" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"oir"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-39"><a href="#cb12-39" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-40"><a href="#cb12-40" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb12-41"><a href="#cb12-41" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-42"><a href="#cb12-42" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-43"><a href="#cb12-43" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb12-44"><a href="#cb12-44" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb12-45"><a href="#cb12-45" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-46"><a href="#cb12-46" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb12-47"><a href="#cb12-47" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-48"><a href="#cb12-48" aria-hidden="true" tabindex="-1"></a>casualties_ond <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>,<span class="st">"ONDMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-49"><a href="#cb12-49" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"ond"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-50"><a href="#cb12-50" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-51"><a href="#cb12-51" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb12-52"><a href="#cb12-52" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-53"><a href="#cb12-53" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-54"><a href="#cb12-54" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb12-55"><a href="#cb12-55" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb12-56"><a href="#cb12-56" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-57"><a href="#cb12-57" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb12-58"><a href="#cb12-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-59"><a href="#cb12-59" aria-hidden="true" tabindex="-1"></a>casualties_aad <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>,<span class="st">"aad-search-results.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-60"><a href="#cb12-60" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(INCIDENT.OR.DEATH.DATE,</span>
<span id="cb12-61"><a href="#cb12-61" aria-hidden="true" tabindex="-1"></a>                HOSTILE.OR.NON.HOSTILE.DEATH.INDICATOR) <span class="sc">%&gt;%</span></span>
<span id="cb12-62"><a href="#cb12-62" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> INCIDENT.OR.DEATH.DATE, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"day"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">"/"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-63"><a href="#cb12-63" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb12-64"><a href="#cb12-64" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(start_date_month, HOSTILE.OR.NON.HOSTILE.DEATH.INDICATOR) <span class="sc">%&gt;%</span></span>
<span id="cb12-65"><a href="#cb12-65" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">count =</span> <span class="fu">n</span>()) <span class="sc">%&gt;%</span></span>
<span id="cb12-66"><a href="#cb12-66" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb12-67"><a href="#cb12-67" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">pivot_wider</span>(<span class="at">id_cols =</span> start_date_month,</span>
<span id="cb12-68"><a href="#cb12-68" aria-hidden="true" tabindex="-1"></a>                     <span class="at">names_from =</span> HOSTILE.OR.NON.HOSTILE.DEATH.INDICATOR,</span>
<span id="cb12-69"><a href="#cb12-69" aria-hidden="true" tabindex="-1"></a>                     <span class="at">values_from =</span> count) <span class="sc">%&gt;%</span></span>
<span id="cb12-70"><a href="#cb12-70" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">TOTL_hostile =</span> <span class="st">'Hostile Death'</span>, <span class="at">TOTL_nonhostile =</span> <span class="st">'Non-Hostile Death'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb12-71"><a href="#cb12-71" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_hostile =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_hostile, <span class="dv">0</span>),</span>
<span id="cb12-72"><a href="#cb12-72" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_nonhostile =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_nonhostile, <span class="dv">0</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-73"><a href="#cb12-73" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_all =</span> <span class="fu">as.numeric</span>(TOTL_hostile) <span class="sc">+</span> <span class="fu">as.numeric</span>(TOTL_nonhostile)) <span class="sc">%&gt;%</span></span>
<span id="cb12-74"><a href="#cb12-74" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(<span class="sc">-</span>TOTL_nonhostile) <span class="sc">%&gt;%</span></span>
<span id="cb12-75"><a href="#cb12-75" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"aad"</span>)</span>
<span id="cb12-76"><a href="#cb12-76" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-77"><a href="#cb12-77" aria-hidden="true" tabindex="-1"></a>casualties_all <span class="ot">&lt;-</span> <span class="fu">rbind</span>(casualties_aad,</span>
<span id="cb12-78"><a href="#cb12-78" aria-hidden="true" tabindex="-1"></a>                        casualties_oef,</span>
<span id="cb12-79"><a href="#cb12-79" aria-hidden="true" tabindex="-1"></a>                        casualties_ofs,</span>
<span id="cb12-80"><a href="#cb12-80" aria-hidden="true" tabindex="-1"></a>                        casualties_oif,</span>
<span id="cb12-81"><a href="#cb12-81" aria-hidden="true" tabindex="-1"></a>                        casualties_oir,</span>
<span id="cb12-82"><a href="#cb12-82" aria-hidden="true" tabindex="-1"></a>                        casualties_ond)</span>
<span id="cb12-83"><a href="#cb12-83" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-84"><a href="#cb12-84" aria-hidden="true" tabindex="-1"></a>casualties_all <span class="ot">&lt;-</span> casualties_all <span class="sc">%&gt;%</span></span>
<span id="cb12-85"><a href="#cb12-85" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(start_date_month) <span class="sc">%&gt;%</span></span>
<span id="cb12-86"><a href="#cb12-86" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">TOTL_hostile_all =</span> <span class="fu">sum</span>(TOTL_hostile),</span>
<span id="cb12-87"><a href="#cb12-87" aria-hidden="true" tabindex="-1"></a>                   <span class="at">TOTL_all_all =</span> <span class="fu">sum</span>(TOTL_all))</span>
<span id="cb12-88"><a href="#cb12-88" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-89"><a href="#cb12-89" aria-hidden="true" tabindex="-1"></a>casualties_all <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(dates, casualties_all) <span class="sc">%&gt;%</span></span>
<span id="cb12-90"><a href="#cb12-90" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_hostile =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_hostile_all, <span class="dv">0</span>),</span>
<span id="cb12-91"><a href="#cb12-91" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_all =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_all_all, <span class="dv">0</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb12-92"><a href="#cb12-92" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month,</span>
<span id="cb12-93"><a href="#cb12-93" aria-hidden="true" tabindex="-1"></a>                TOTL_hostile, TOTL_all) <span class="sc">%&gt;%</span></span>
<span id="cb12-94"><a href="#cb12-94" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_hostileL1 =</span> <span class="fu">lag</span>(TOTL_hostile),</span>
<span id="cb12-95"><a href="#cb12-95" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_allL1 =</span> <span class="fu">lag</span>(TOTL_all),</span>
<span id="cb12-96"><a href="#cb12-96" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_hostileL2 =</span> <span class="fu">lag</span>(TOTL_hostileL1),</span>
<span id="cb12-97"><a href="#cb12-97" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_allL2 =</span> <span class="fu">lag</span>(TOTL_allL1),</span>
<span id="cb12-98"><a href="#cb12-98" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_hostile_chg =</span> TOTL_hostileL2 <span class="sc">-</span> TOTL_hostileL1,</span>
<span id="cb12-99"><a href="#cb12-99" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_all_chg =</span> TOTL_allL2 <span class="sc">-</span> TOTL_allL1)</span>
<span id="cb12-100"><a href="#cb12-100" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-101"><a href="#cb12-101" aria-hidden="true" tabindex="-1"></a><span class="co"># Merge</span></span>
<span id="cb12-102"><a href="#cb12-102" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, casualties_all)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="collateral-damage" class="level2">
<h2 class="anchored" data-anchor-id="collateral-damage">Collateral damage</h2>
<p>Urban areas mean low tech</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-10_66c788ccab6a3f726f08191a79b89b0d">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>gis <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"coordinates.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_id, urban, forested, mountainous) <span class="sc">%&gt;%</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">urban_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(urban <span class="sc">==</span> <span class="dv">2</span>, <span class="dv">1</span>, <span class="dv">0</span>))</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, gis)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
</section>
<section id="final-clean" class="level1">
<h1>Final clean</h1>
<p>Fix variable types</p>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-11_7fe1d7e0e1ef94b4efd62842efc1b1b5">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="fu">str</span>(df_interv)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>'data.frame':   310 obs. of  76 variables:
 $ wikidata_name              : chr  "1989 Philippine coup attempt" "Operation Uphold Democracy" "Operation Secure Tomorrow" "2017 al-Jinah airstrike" ...
 $ wikidata_id                : chr  "Q4585384" "Q2026486" "Q7097528" "Q28983702" ...
 $ parent_name                : chr  "1989 Philippine coup attempt" "1991 Haitian coup d'état" "2004 Haitian coup d'état" "Syrian Civil War" ...
 $ parent_id                  : chr  "Q4585384" "Q4586873" "Q2883469" "Q178810" ...
 $ parent_icb                 : chr  NA "HAITI MIL. REGIME" NA "SYRIA CHEMICAL WEAPONS" ...
 $ parent_imi                 : chr  "US aids Phillippine government after coup attempt (AP, UPI, Xinh)" "US restores democratically elected government in Haiti  (UPI, AP)" "US aids in restoring order in Haiti (AP, AFP)" NA ...
 $ parent_mids                : chr  NA "4016" NA NA ...
 $ parent_mip                 : chr  "Philippines Coup Attempt" "Operation Uphold Democracy" "Operation Secure Tomorrow" "c(\"Syrian Civil War/Counter IS\", \"U.S. involvement in Syrian Civil War\")" ...
 $ parent_mips                : chr  NA "Operation Uphold Democracy" NA NA ...
 $ parent_rand                : chr  NA "Operation Uphold Democracy" "Operation Secure Tomorrow" "Operation Inherent Resolve" ...
 $ parent_start               : Date, format: "1989-12-01" "1991-09-29" ...
 $ means_drones               : int  0 0 0 1 0 0 0 0 1 0 ...
 $ means_airtoair             : int  1 0 0 0 0 0 0 0 0 1 ...
 $ means_cruisemissiles       : int  0 0 0 0 1 1 0 0 1 0 ...
 $ means_aerialbombing        : int  0 0 0 1 0 0 1 1 1 0 ...
 $ means_closeairsupport      : int  0 0 0 0 0 0 0 0 1 0 ...
 $ means_groundtroops         : int  1 1 1 0 0 0 0 0 0 0 ...
 $ means_paramilitary         : int  0 1 1 0 0 0 0 0 1 0 ...
 $ lat                        : num  14.6 19 18.6 36.1 34.5 ...
 $ lon                        : num  121 -72.3 -72.3 36.8 36.9 ...
 $ year                       : num  1989 1994 2004 2017 2017 ...
 $ start_date                 : Date, format: "1989-12-01" "1994-09-19" ...
 $ end_date                   : chr  "1989-12-09" "1995-03-31" "2004-07-01" "2017-03-16" ...
 $ duration                   : int  8 193 123 0 0 0 30 8 274 0 ...
 $ daysinto_parent            : num  0 1086 24 2193 2245 ...
 $ allycount1                 : num  1 2 3 0 0 2 4 2 0 1 ...
 $ multilateral1              : num  1 1 1 0 0 1 1 1 0 1 ...
 $ casualties_sideA           : int  NA 1 0 NA NA NA 33 26 0 0 ...
 $ casualties_sideB           : int  NA 301 NA NA NA NA 493 455 19 0 ...
 $ casualties_civilian        : chr  NA NA NA NA ...
 $ casualties_us              : int  NA 1 0 NA NA NA NA NA 0 0 ...
 $ sideB_state_count          : int  1 1 0 1 1 1 0 0 1 1 ...
 $ sideB_nonstate_all_count   : num  1 0 1 1 0 0 1 1 2 0 ...
 $ sideB_nonstate_major_count : int  0 0 0 1 0 0 1 1 1 0 ...
 $ sideB_nonstate_minor_count : int  1 0 1 0 0 0 0 0 1 0 ...
 $ sideB_state_ratio          : num  0.5 1 0 0.5 1 ...
 $ sideB_statenonstate_ordinal: num  1 2 0 1 2 2 0 0 1 2 ...
 $ sideB_state_binary         : num  1 1 0 1 1 1 0 0 1 1 ...
 $ sideB_nonstate_all_binary  : num  1 0 1 1 0 0 1 1 1 0 ...
 $ sideB_nonstate_major_binary: num  0 0 0 1 0 0 1 1 1 0 ...
 $ sideB_nonstate_minor_binary: num  1 0 1 0 0 0 0 0 1 0 ...
 $ start_date_month           : chr  "1989-12" "1994-09" "2004-02" "2017-03" ...
 $ month                      : chr  "12" "09" "02" "03" ...
 $ yearmonth                  : int  198912 199409 200402 201703 201705 201804 201510 201602 201901 201706 ...
 $ presidentid                : chr  "George Bush" "William J. Clinton" "George W. Bush" "Donald Trump" ...
 $ approve                    : num  68.5 41.3 51.3 39.8 39.4 ...
 $ disapprove                 : num  17.5 51.3 44.7 55 55 ...
 $ difference                 : num  51 -10 6.67 15.25 15.6 ...
 $ approveL1                  : num  66 41 55.5 41.5 40.5 ...
 $ approve_detrend            : num  6.75 -17.14 1.2 -2.31 -2.63 ...
 $ appch                      : num  2.5 0.333 -4.167 -1.75 -1.1 ...
 $ appchpc                    : num  3.788 0.813 -7.508 -4.22 -2.72 ...
 $ disappch                   : num  -2 1.83 4.42 2.25 1.75 ...
 $ disappchpc                 : num  -10.26 3.7 10.97 4.27 3.29 ...
 $ demparty                   : int  0 1 0 0 0 0 1 1 0 0 ...
 $ term2                      : int  0 0 0 0 0 0 1 1 0 0 ...
 $ misery                     : num  10.05 8.86 7.29 6.88 6.17 ...
 $ miseryL1                   : num  10.06 8.9 7.63 7.44 6.6 ...
 $ elecmonth                  : int  0 0 0 0 0 0 0 0 0 0 ...
 $ elecyear                   : int  0 0 1 0 0 0 0 1 0 0 ...
 $ reelecyear                 : int  0 0 1 0 0 0 0 0 0 0 ...
 $ tenure                     : int  12 21 38 2 4 15 82 86 24 5 ...
 $ firstyear                  : int  1 0 0 1 1 1 0 0 1 1 ...
 $ disapproveL1               : num  19.5 49.5 40.2 52.8 53.2 ...
 $ TOTL_hostile               : num  0 0 13 0 1 1 1 0 4 3 ...
 $ TOTL_all                   : num  0 0 23 5 2 2 9 0 4 3 ...
 $ TOTL_hostileL1             : num  0 0 39 0 4 0 0 1 1 1 ...
 $ TOTL_allL1                 : num  0 0 55 1 6 10 2 3 4 2 ...
 $ TOTL_hostileL2             : num  0 0 24 1 0 0 3 6 5 4 ...
 $ TOTL_allL2                 : num  0 0 41 3 5 1 3 6 5 6 ...
 $ TOTL_hostile_chg           : num  0 0 -15 1 -4 0 3 5 4 3 ...
 $ TOTL_all_chg               : num  0 0 -14 2 -1 -9 1 3 1 4 ...
 $ urban                      : int  2 1 0 1 2 0 0 0 0 0 ...
 $ forested                   : int  0 0 0 0 0 0 0 0 0 0 ...
 $ mountainous                : int  0 1 1 1 1 1 1 1 1 1 ...
 $ urban_binary               : num  1 0 0 0 1 0 0 0 0 0 ...</code></pre>
</div>
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df_interv <span class="sc">%&gt;%</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate_at</span>(<span class="fu">c</span>(<span class="st">"wikidata_id"</span>,</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"parent_id"</span>,</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"multilateral1"</span>,</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_statenonstate_ordinal"</span>,</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_state_binary"</span>,</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_nonstate_all_binary"</span>,</span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_nonstate_major_binary"</span>,</span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_nonstate_minor_binary"</span>,</span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"demparty"</span>,</span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"urban"</span>,</span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"urban_binary"</span>,</span>
<span id="cb16-13"><a href="#cb16-13" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"forested"</span>,</span>
<span id="cb16-14"><a href="#cb16-14" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"mountainous"</span>), factor) <span class="sc">%&gt;%</span></span>
<span id="cb16-15"><a href="#cb16-15" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="save" class="level1">
<h1>Save</h1>
<div class="cell" data-hash="04_Model_Prep_cache/html/unnamed-chunk-12_a57b8771aecb6e0082c097caa7206ed9">
<details>
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write.csv</span>(df_interv, <span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"MONSTr.csv"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<!-- -->

</section>

</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
  const icon = "";
  const anchorJS = new window.AnchorJS();
  anchorJS.options = {
    placement: 'right',
    icon: icon
  };
  anchorJS.add('.anchored');
  const clipboard = new window.ClipboardJS('.code-copy-button', {
    target: function(trigger) {
      return trigger.previousElementSibling;
    }
  });
  clipboard.on('success', function(e) {
    // button target
    const button = e.trigger;
    // don't keep focus
    button.blur();
    // flash "checked"
    button.classList.add('code-copy-button-checked');
    var currentTitle = button.getAttribute("title");
    button.setAttribute("title", "Copied!");
    setTimeout(function() {
      button.setAttribute("title", currentTitle);
      button.classList.remove('code-copy-button-checked');
    }, 1000);
    // clear code selection
    e.clearSelection();
  });
  const viewSource = window.document.getElementById('quarto-view-source') ||
                     window.document.getElementById('quarto-code-tools-source');
  if (viewSource) {
    const sourceUrl = viewSource.getAttribute("data-quarto-source-url");
    viewSource.addEventListener("click", function(e) {
      if (sourceUrl) {
        // rstudio viewer pane
        if (/\bcapabilities=\b/.test(window.location)) {
          window.open(sourceUrl);
        } else {
          window.location.href = sourceUrl;
        }
      } else {
        const modal = new bootstrap.Modal(document.getElementById('quarto-embedded-source-code-modal'));
        modal.show();
      }
      return false;
    });
  }
  function toggleCodeHandler(show) {
    return function(e) {
      const detailsSrc = window.document.querySelectorAll(".cell > details > .sourceCode");
      for (let i=0; i<detailsSrc.length; i++) {
        const details = detailsSrc[i].parentElement;
        if (show) {
          details.open = true;
        } else {
          details.removeAttribute("open");
        }
      }
      const cellCodeDivs = window.document.querySelectorAll(".cell > .sourceCode");
      const fromCls = show ? "hidden" : "unhidden";
      const toCls = show ? "unhidden" : "hidden";
      for (let i=0; i<cellCodeDivs.length; i++) {
        const codeDiv = cellCodeDivs[i];
        if (codeDiv.classList.contains(fromCls)) {
          codeDiv.classList.remove(fromCls);
          codeDiv.classList.add(toCls);
        } 
      }
      return false;
    }
  }
  const hideAllCode = window.document.getElementById("quarto-hide-all-code");
  if (hideAllCode) {
    hideAllCode.addEventListener("click", toggleCodeHandler(false));
  }
  const showAllCode = window.document.getElementById("quarto-show-all-code");
  if (showAllCode) {
    showAllCode.addEventListener("click", toggleCodeHandler(true));
  }
  function tippyHover(el, contentFn) {
    const config = {
      allowHTML: true,
      content: contentFn,
      maxWidth: 500,
      delay: 100,
      arrow: false,
      appendTo: function(el) {
          return el.parentElement;
      },
      interactive: true,
      interactiveBorder: 10,
      theme: 'quarto',
      placement: 'bottom-start'
    };
    window.tippy(el, config); 
  }
  const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
  for (var i=0; i<noterefs.length; i++) {
    const ref = noterefs[i];
    tippyHover(ref, function() {
      let href = ref.getAttribute('href');
      try { href = new URL(href).hash; } catch {}
      const id = href.replace(/^#\/?/, "");
      const note = window.document.getElementById(id);
      return note.innerHTML;
    });
  }
  var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
  for (var i=0; i<bibliorefs.length; i++) {
    const ref = bibliorefs[i];
    const cites = ref.parentNode.getAttribute('data-cites').split(' ');
    tippyHover(ref, function() {
      var popup = window.document.createElement('div');
      cites.forEach(function(cite) {
        var citeDiv = window.document.createElement('div');
        citeDiv.classList.add('hanging-indent');
        citeDiv.classList.add('csl-entry');
        var biblioDiv = window.document.getElementById('ref-' + cite);
        if (biblioDiv) {
          citeDiv.innerHTML = biblioDiv.innerHTML;
        }
        popup.appendChild(citeDiv);
      });
      return popup.innerHTML;
    });
  }
});
</script><div class="modal fade" id="quarto-embedded-source-code-modal" tabindex="-1" aria-labelledby="quarto-embedded-source-code-modal-label" aria-hidden="true"><div class="modal-dialog modal-dialog-scrollable"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="quarto-embedded-source-code-modal-label">Source Code</h5><button class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div class="">
<div class="sourceCode" id="cb18" data-shortcodes="false"><pre class="sourceCode markdown code-with-copy"><code class="sourceCode markdown"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="co">---</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="an">title:</span><span class="co"> "Model Prep"</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a><span class="an">author:</span><span class="co"> "J Andres Gannon"</span></span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a><span class="an">format:</span></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a><span class="co">  html:</span></span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a><span class="co">    title-block-banner: true</span></span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a><span class="co">    toc: true</span></span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a><span class="co">    toc-location: right</span></span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a><span class="co">    toc-depth: 2</span></span>
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a><span class="co">    html-math-method: katex</span></span>
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a><span class="co">    css: styles.css</span></span>
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a><span class="co">    citations-hover: true</span></span>
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a><span class="co">    footnotes-hover: true</span></span>
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a><span class="co">    code-tools: true</span></span>
<span id="cb18-15"><a href="#cb18-15" aria-hidden="true" tabindex="-1"></a><span class="co">    code-fold: true</span></span>
<span id="cb18-16"><a href="#cb18-16" aria-hidden="true" tabindex="-1"></a><span class="co">    code-summary: "Show the code"</span></span>
<span id="cb18-17"><a href="#cb18-17" aria-hidden="true" tabindex="-1"></a><span class="co">    code-overflow: wrap</span></span>
<span id="cb18-18"><a href="#cb18-18" aria-hidden="true" tabindex="-1"></a><span class="co">    code-copy: true</span></span>
<span id="cb18-19"><a href="#cb18-19" aria-hidden="true" tabindex="-1"></a><span class="an">editor:</span><span class="co"> visual</span></span>
<span id="cb18-20"><a href="#cb18-20" aria-hidden="true" tabindex="-1"></a><span class="an">execute:</span></span>
<span id="cb18-21"><a href="#cb18-21" aria-hidden="true" tabindex="-1"></a><span class="co">  echo: true</span></span>
<span id="cb18-22"><a href="#cb18-22" aria-hidden="true" tabindex="-1"></a><span class="co">  warning: false</span></span>
<span id="cb18-23"><a href="#cb18-23" aria-hidden="true" tabindex="-1"></a><span class="co">  cache: true</span></span>
<span id="cb18-24"><a href="#cb18-24" aria-hidden="true" tabindex="-1"></a><span class="an">date:</span><span class="co"> "`r format(Sys.Date(), '%B %d, %Y')`"</span></span>
<span id="cb18-25"><a href="#cb18-25" aria-hidden="true" tabindex="-1"></a><span class="an">bibliography:</span><span class="co"> ../paper/MONSTr.bib</span></span>
<span id="cb18-26"><a href="#cb18-26" aria-hidden="true" tabindex="-1"></a><span class="co">---</span></span>
<span id="cb18-27"><a href="#cb18-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-28"><a href="#cb18-28" aria-hidden="true" tabindex="-1"></a><span class="fu"># Set up</span></span>
<span id="cb18-31"><a href="#cb18-31" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-32"><a href="#cb18-32" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(magrittr)</span>
<span id="cb18-33"><a href="#cb18-33" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb18-34"><a href="#cb18-34" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-35"><a href="#cb18-35" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-36"><a href="#cb18-36" aria-hidden="true" tabindex="-1"></a><span class="fu"># Intervention list</span></span>
<span id="cb18-37"><a href="#cb18-37" aria-hidden="true" tabindex="-1"></a>Start by loading the cleaned intervention list</span>
<span id="cb18-40"><a href="#cb18-40" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-41"><a href="#cb18-41" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"02a_interventions_newdata_dbpedia.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-42"><a href="#cb18-42" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_name, wikidata_id,</span>
<span id="cb18-43"><a href="#cb18-43" aria-hidden="true" tabindex="-1"></a>                location_name, lat, lon,</span>
<span id="cb18-44"><a href="#cb18-44" aria-hidden="true" tabindex="-1"></a>                start_date, end_date, duration,</span>
<span id="cb18-45"><a href="#cb18-45" aria-hidden="true" tabindex="-1"></a>                belligerent_sideA, belligerent_sideB,</span>
<span id="cb18-46"><a href="#cb18-46" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"means_"</span>),</span>
<span id="cb18-47"><a href="#cb18-47" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"casualties_"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-48"><a href="#cb18-48" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb18-49"><a href="#cb18-49" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-50"><a href="#cb18-50" aria-hidden="true" tabindex="-1"></a><span class="co"># Merge with parent observations which gives us the current list of operations</span></span>
<span id="cb18-51"><a href="#cb18-51" aria-hidden="true" tabindex="-1"></a>ops <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"03_interventions_newdata_childof_operations.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-52"><a href="#cb18-52" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(<span class="sc">-</span>X) <span class="sc">%&gt;%</span></span>
<span id="cb18-53"><a href="#cb18-53" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb18-54"><a href="#cb18-54" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-55"><a href="#cb18-55" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(ops, df)</span>
<span id="cb18-56"><a href="#cb18-56" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-57"><a href="#cb18-57" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-58"><a href="#cb18-58" aria-hidden="true" tabindex="-1"></a><span class="fu">## Clean</span></span>
<span id="cb18-59"><a href="#cb18-59" aria-hidden="true" tabindex="-1"></a>Subset to just the US, and drop dyads that don't involve the US</span>
<span id="cb18-62"><a href="#cb18-62" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-63"><a href="#cb18-63" aria-hidden="true" tabindex="-1"></a>ally <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb18-64"><a href="#cb18-64" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(wikidata_name, wikidata_id) <span class="sc">%&gt;%</span></span>
<span id="cb18-65"><a href="#cb18-65" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">participants =</span> dplyr<span class="sc">::</span><span class="fu">n_distinct</span>(belligerent_sideA)) <span class="sc">%&gt;%</span></span>
<span id="cb18-66"><a href="#cb18-66" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">participants =</span> participants<span class="dv">-1</span>)</span>
<span id="cb18-67"><a href="#cb18-67" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-68"><a href="#cb18-68" aria-hidden="true" tabindex="-1"></a>ally <span class="sc">%&gt;%</span></span>
<span id="cb18-69"><a href="#cb18-69" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>()</span>
<span id="cb18-70"><a href="#cb18-70" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-71"><a href="#cb18-71" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, ally) <span class="sc">%&gt;%</span></span>
<span id="cb18-72"><a href="#cb18-72" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">belligerent_sideA =</span> <span class="st">"United States"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-73"><a href="#cb18-73" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">ccode1 =</span> <span class="fu">as.numeric</span>(<span class="dv">2</span>),</span>
<span id="cb18-74"><a href="#cb18-74" aria-hidden="true" tabindex="-1"></a>                <span class="at">cname1 =</span> <span class="st">"USA"</span>,</span>
<span id="cb18-75"><a href="#cb18-75" aria-hidden="true" tabindex="-1"></a>                <span class="at">qcode1 =</span> <span class="st">"Q30"</span>,</span>
<span id="cb18-76"><a href="#cb18-76" aria-hidden="true" tabindex="-1"></a>                <span class="at">multilateral1 =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(participants <span class="sc">&gt;</span> <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-77"><a href="#cb18-77" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">belligerent1 =</span> belligerent_sideA,</span>
<span id="cb18-78"><a href="#cb18-78" aria-hidden="true" tabindex="-1"></a>                <span class="at">belligerent2 =</span> belligerent_sideB,</span>
<span id="cb18-79"><a href="#cb18-79" aria-hidden="true" tabindex="-1"></a>                <span class="at">allycount1 =</span> participants) <span class="sc">%&gt;%</span></span>
<span id="cb18-80"><a href="#cb18-80" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb18-81"><a href="#cb18-81" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-82"><a href="#cb18-82" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-83"><a href="#cb18-83" aria-hidden="true" tabindex="-1"></a><span class="fu">## Quick checks</span></span>
<span id="cb18-84"><a href="#cb18-84" aria-hidden="true" tabindex="-1"></a>Intervention that span more than a year. Make a temporary variable for start year</span>
<span id="cb18-87"><a href="#cb18-87" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-88"><a href="#cb18-88" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%&gt;%</span></span>
<span id="cb18-89"><a href="#cb18-89" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_name, start_date, end_date) <span class="sc">%&gt;%</span></span>
<span id="cb18-90"><a href="#cb18-90" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">year_start =</span> <span class="fu">format</span>(<span class="fu">as.Date</span>(start_date, <span class="at">format=</span><span class="st">"%Y-%m-%d"</span>),<span class="st">"%Y"</span>),</span>
<span id="cb18-91"><a href="#cb18-91" aria-hidden="true" tabindex="-1"></a>                <span class="at">year_end =</span> <span class="fu">format</span>(<span class="fu">as.Date</span>(end_date, <span class="at">format=</span><span class="st">"%Y-%m-%d"</span>),<span class="st">"%Y"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-92"><a href="#cb18-92" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">filter</span>(year_end <span class="sc">&gt;</span> year_start) <span class="sc">%&gt;%</span></span>
<span id="cb18-93"><a href="#cb18-93" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(<span class="sc">!</span>dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"year_"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-94"><a href="#cb18-94" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>() <span class="sc">%&gt;%</span></span>
<span id="cb18-95"><a href="#cb18-95" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>(<span class="at">filter =</span> <span class="st">"top"</span>)</span>
<span id="cb18-96"><a href="#cb18-96" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-97"><a href="#cb18-97" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb18-98"><a href="#cb18-98" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">year =</span> <span class="fu">as.numeric</span>(<span class="fu">format</span>(<span class="fu">as.Date</span>(start_date, <span class="at">format=</span><span class="st">"%Y-%m-%d"</span>),<span class="st">"%Y"</span>)))</span>
<span id="cb18-99"><a href="#cb18-99" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-100"><a href="#cb18-100" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-101"><a href="#cb18-101" aria-hidden="true" tabindex="-1"></a><span class="fu"># Prep variables</span></span>
<span id="cb18-102"><a href="#cb18-102" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-103"><a href="#cb18-103" aria-hidden="true" tabindex="-1"></a><span class="fu">## Actors</span></span>
<span id="cb18-104"><a href="#cb18-104" aria-hidden="true" tabindex="-1"></a>Get ccode for state actors</span>
<span id="cb18-107"><a href="#cb18-107" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-108"><a href="#cb18-108" aria-hidden="true" tabindex="-1"></a>qcodes <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"belligerent_list.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-109"><a href="#cb18-109" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">filter</span>(<span class="fu">is.na</span>(ccode_wrong)) <span class="sc">%&gt;%</span></span>
<span id="cb18-110"><a href="#cb18-110" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent, ccode, cname, Qcode) <span class="sc">%&gt;%</span></span>
<span id="cb18-111"><a href="#cb18-111" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">belligerent2 =</span> belligerent,</span>
<span id="cb18-112"><a href="#cb18-112" aria-hidden="true" tabindex="-1"></a>                <span class="at">ccode2 =</span> ccode,</span>
<span id="cb18-113"><a href="#cb18-113" aria-hidden="true" tabindex="-1"></a>                <span class="at">cname2 =</span> cname,</span>
<span id="cb18-114"><a href="#cb18-114" aria-hidden="true" tabindex="-1"></a>                <span class="at">qcode2 =</span> Qcode)</span>
<span id="cb18-115"><a href="#cb18-115" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-116"><a href="#cb18-116" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, qcodes) <span class="sc">%&gt;%</span></span>
<span id="cb18-117"><a href="#cb18-117" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_nonstate =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(<span class="fu">is.na</span>(ccode2), <span class="dv">1</span>, <span class="dv">0</span>))</span>
<span id="cb18-118"><a href="#cb18-118" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-119"><a href="#cb18-119" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%&gt;%</span></span>
<span id="cb18-120"><a href="#cb18-120" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent2, ccode2, cname2) <span class="sc">%&gt;%</span></span>
<span id="cb18-121"><a href="#cb18-121" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>() <span class="sc">%&gt;%</span></span>
<span id="cb18-122"><a href="#cb18-122" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">arrange</span>(ccode2) <span class="sc">%&gt;%</span></span>
<span id="cb18-123"><a href="#cb18-123" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>(<span class="at">filter =</span> <span class="st">"top"</span>)</span>
<span id="cb18-124"><a href="#cb18-124" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-125"><a href="#cb18-125" aria-hidden="true" tabindex="-1"></a><span class="co"># New list of sideB non-state actor info</span></span>
<span id="cb18-126"><a href="#cb18-126" aria-hidden="true" tabindex="-1"></a>sideb_nonstate <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"nonstate_actors.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-127"><a href="#cb18-127" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">sideB_nonstate_major =</span> X) <span class="sc">%&gt;%</span></span>
<span id="cb18-128"><a href="#cb18-128" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent2, qcode2, sideB_nonstate_major)</span>
<span id="cb18-129"><a href="#cb18-129" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-130"><a href="#cb18-130" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, sideb_nonstate)</span>
<span id="cb18-131"><a href="#cb18-131" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-132"><a href="#cb18-132" aria-hidden="true" tabindex="-1"></a><span class="co"># Make all state actors 0 for nonstate major</span></span>
<span id="cb18-133"><a href="#cb18-133" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb18-134"><a href="#cb18-134" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_nonstate_major =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(sideB_nonstate_major), <span class="dv">0</span>, sideB_nonstate_major))</span>
<span id="cb18-135"><a href="#cb18-135" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-136"><a href="#cb18-136" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%&gt;%</span></span>
<span id="cb18-137"><a href="#cb18-137" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(belligerent2, cname2, sideB_nonstate, sideB_nonstate_major) <span class="sc">%&gt;%</span></span>
<span id="cb18-138"><a href="#cb18-138" aria-hidden="true" tabindex="-1"></a>  DT<span class="sc">::</span><span class="fu">datatable</span>()</span>
<span id="cb18-139"><a href="#cb18-139" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-140"><a href="#cb18-140" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-141"><a href="#cb18-141" aria-hidden="true" tabindex="-1"></a>Match parents to the main data, including the start date of the parent intervention and days into the parent intervention</span>
<span id="cb18-144"><a href="#cb18-144" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-145"><a href="#cb18-145" aria-hidden="true" tabindex="-1"></a><span class="co"># Pull all interventions so we have the start dates</span></span>
<span id="cb18-146"><a href="#cb18-146" aria-hidden="true" tabindex="-1"></a>df_parent <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"02a_interventions_newdata_dbpedia.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-147"><a href="#cb18-147" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_id, start_date) <span class="sc">%&gt;%</span></span>
<span id="cb18-148"><a href="#cb18-148" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">parent_id =</span> <span class="st">"wikidata_id"</span>,</span>
<span id="cb18-149"><a href="#cb18-149" aria-hidden="true" tabindex="-1"></a>                <span class="at">parent_start =</span> <span class="st">"start_date"</span>)</span>
<span id="cb18-150"><a href="#cb18-150" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-151"><a href="#cb18-151" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df, df_parent)</span>
<span id="cb18-152"><a href="#cb18-152" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-153"><a href="#cb18-153" aria-hidden="true" tabindex="-1"></a><span class="co"># Calculate how many days into the parent intervention the child intervention occurred</span></span>
<span id="cb18-154"><a href="#cb18-154" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb18-155"><a href="#cb18-155" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date =</span> <span class="fu">as.Date</span>(start_date, <span class="st">"%Y-%m-%d"</span>),</span>
<span id="cb18-156"><a href="#cb18-156" aria-hidden="true" tabindex="-1"></a>                <span class="at">parent_start =</span> <span class="fu">as.Date</span>(parent_start, <span class="st">"%Y-%m-%d"</span>),</span>
<span id="cb18-157"><a href="#cb18-157" aria-hidden="true" tabindex="-1"></a>                <span class="at">daysinto_parent =</span> <span class="fu">difftime</span>(start_date, parent_start, <span class="at">units =</span> <span class="fu">c</span>(<span class="st">"days"</span>)),</span>
<span id="cb18-158"><a href="#cb18-158" aria-hidden="true" tabindex="-1"></a>                <span class="at">daysinto_parent =</span> <span class="fu">as.numeric</span>(daysinto_parent, <span class="at">units =</span> <span class="st">"days"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-159"><a href="#cb18-159" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb18-160"><a href="#cb18-160" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-161"><a href="#cb18-161" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-162"><a href="#cb18-162" aria-hidden="true" tabindex="-1"></a><span class="fu"># Condense UoA</span></span>
<span id="cb18-163"><a href="#cb18-163" aria-hidden="true" tabindex="-1"></a>Collapse the data from intervention-dyad to intervention</span>
<span id="cb18-164"><a href="#cb18-164" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-167"><a href="#cb18-167" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-168"><a href="#cb18-168" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb18-169"><a href="#cb18-169" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"wikidata_"</span>), dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"parent_"</span>),</span>
<span id="cb18-170"><a href="#cb18-170" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"means_"</span>),</span>
<span id="cb18-171"><a href="#cb18-171" aria-hidden="true" tabindex="-1"></a>                lat, lon, </span>
<span id="cb18-172"><a href="#cb18-172" aria-hidden="true" tabindex="-1"></a>                year, start_date, end_date, duration, parent_start, daysinto_parent,</span>
<span id="cb18-173"><a href="#cb18-173" aria-hidden="true" tabindex="-1"></a>                allycount1, multilateral1,</span>
<span id="cb18-174"><a href="#cb18-174" aria-hidden="true" tabindex="-1"></a>                dplyr<span class="sc">::</span><span class="fu">starts_with</span>(<span class="st">"casualties_"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-175"><a href="#cb18-175" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb18-176"><a href="#cb18-176" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-177"><a href="#cb18-177" aria-hidden="true" tabindex="-1"></a>df_target <span class="ot">&lt;-</span> df <span class="sc">%&gt;%</span></span>
<span id="cb18-178"><a href="#cb18-178" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_id,</span>
<span id="cb18-179"><a href="#cb18-179" aria-hidden="true" tabindex="-1"></a>                cname2, sideB_nonstate, sideB_nonstate_major) <span class="sc">%&gt;%</span></span>
<span id="cb18-180"><a href="#cb18-180" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(wikidata_id) <span class="sc">%&gt;%</span></span>
<span id="cb18-181"><a href="#cb18-181" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">sideB_state_count =</span> dplyr<span class="sc">::</span><span class="fu">n_distinct</span>(cname2, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb18-182"><a href="#cb18-182" aria-hidden="true" tabindex="-1"></a>                   <span class="at">sideB_nonstate_all_count =</span> <span class="fu">sum</span>(sideB_nonstate, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb18-183"><a href="#cb18-183" aria-hidden="true" tabindex="-1"></a>                   <span class="at">sideB_nonstate_major_count =</span> <span class="fu">sum</span>(sideB_nonstate_major <span class="sc">==</span> <span class="dv">2</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb18-184"><a href="#cb18-184" aria-hidden="true" tabindex="-1"></a>                   <span class="at">sideB_nonstate_minor_count =</span> <span class="fu">sum</span>(sideB_nonstate_major <span class="sc">==</span> <span class="dv">1</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-185"><a href="#cb18-185" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_state_ratio =</span> sideB_state_count<span class="sc">/</span>(sideB_state_count <span class="sc">+</span> sideB_nonstate_all_count)) <span class="sc">%&gt;%</span></span>
<span id="cb18-186"><a href="#cb18-186" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_statenonstate_ordinal =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_ratio <span class="sc">==</span> <span class="dv">1</span>, </span>
<span id="cb18-187"><a href="#cb18-187" aria-hidden="true" tabindex="-1"></a>                                                              <span class="dv">0</span>, <span class="dv">0</span>),</span>
<span id="cb18-188"><a href="#cb18-188" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_statenonstate_ordinal =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_ratio <span class="sc">&lt;</span> <span class="dv">1</span> <span class="sc">&amp;</span> sideB_state_ratio <span class="sc">&gt;</span> <span class="dv">0</span>, </span>
<span id="cb18-189"><a href="#cb18-189" aria-hidden="true" tabindex="-1"></a>                                                              <span class="dv">1</span>, sideB_statenonstate_ordinal),</span>
<span id="cb18-190"><a href="#cb18-190" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_statenonstate_ordinal =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_ratio <span class="sc">==</span> <span class="dv">1</span>,</span>
<span id="cb18-191"><a href="#cb18-191" aria-hidden="true" tabindex="-1"></a>                                                              <span class="dv">2</span>, sideB_statenonstate_ordinal)) <span class="sc">%&gt;%</span></span>
<span id="cb18-192"><a href="#cb18-192" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">sideB_state_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_state_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb18-193"><a href="#cb18-193" aria-hidden="true" tabindex="-1"></a>                                                    <span class="dv">1</span>, <span class="dv">0</span>),</span>
<span id="cb18-194"><a href="#cb18-194" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_nonstate_all_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_nonstate_all_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb18-195"><a href="#cb18-195" aria-hidden="true" tabindex="-1"></a>                                                       <span class="dv">1</span>, <span class="dv">0</span>),</span>
<span id="cb18-196"><a href="#cb18-196" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_nonstate_major_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_nonstate_major_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb18-197"><a href="#cb18-197" aria-hidden="true" tabindex="-1"></a>                                                       <span class="dv">1</span>, <span class="dv">0</span>),</span>
<span id="cb18-198"><a href="#cb18-198" aria-hidden="true" tabindex="-1"></a>                <span class="at">sideB_nonstate_minor_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(sideB_nonstate_minor_count <span class="sc">&gt;</span> <span class="dv">0</span>,</span>
<span id="cb18-199"><a href="#cb18-199" aria-hidden="true" tabindex="-1"></a>                                                       <span class="dv">1</span>, <span class="dv">0</span>))</span>
<span id="cb18-200"><a href="#cb18-200" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-201"><a href="#cb18-201" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, df_target)</span>
<span id="cb18-202"><a href="#cb18-202" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-203"><a href="#cb18-203" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-204"><a href="#cb18-204" aria-hidden="true" tabindex="-1"></a><span class="fu"># Add variables</span></span>
<span id="cb18-205"><a href="#cb18-205" aria-hidden="true" tabindex="-1"></a><span class="fu">## Public approval</span></span>
<span id="cb18-208"><a href="#cb18-208" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-209"><a href="#cb18-209" aria-hidden="true" tabindex="-1"></a>approval <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"approval.csv"</span>))</span>
<span id="cb18-210"><a href="#cb18-210" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-211"><a href="#cb18-211" aria-hidden="true" tabindex="-1"></a><span class="co"># Prep date variables</span></span>
<span id="cb18-212"><a href="#cb18-212" aria-hidden="true" tabindex="-1"></a>approval <span class="ot">&lt;-</span> approval <span class="sc">%&gt;%</span></span>
<span id="cb18-213"><a href="#cb18-213" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-214"><a href="#cb18-214" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month),</span>
<span id="cb18-215"><a href="#cb18-215" aria-hidden="true" tabindex="-1"></a>                <span class="at">approveL1 =</span> dplyr<span class="sc">::</span><span class="fu">lag</span>(approve),</span>
<span id="cb18-216"><a href="#cb18-216" aria-hidden="true" tabindex="-1"></a>                <span class="at">disapproveL1 =</span> dplyr<span class="sc">::</span><span class="fu">lag</span>(disapprove))</span>
<span id="cb18-217"><a href="#cb18-217" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-218"><a href="#cb18-218" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df_interv <span class="sc">%&gt;%</span></span>
<span id="cb18-219"><a href="#cb18-219" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date_month =</span> <span class="fu">substr</span>(start_date, <span class="at">start =</span> <span class="dv">1</span>, <span class="at">stop =</span> <span class="dv">7</span>))</span>
<span id="cb18-220"><a href="#cb18-220" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-221"><a href="#cb18-221" aria-hidden="true" tabindex="-1"></a><span class="co"># Merge</span></span>
<span id="cb18-222"><a href="#cb18-222" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, approval)</span>
<span id="cb18-223"><a href="#cb18-223" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-224"><a href="#cb18-224" aria-hidden="true" tabindex="-1"></a><span class="co"># Add Biden events</span></span>
<span id="cb18-225"><a href="#cb18-225" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df_interv <span class="sc">%&gt;%</span></span>
<span id="cb18-226"><a href="#cb18-226" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">presidentid =</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(presidentid), <span class="st">"Joseph Biden"</span>, presidentid))</span>
<span id="cb18-227"><a href="#cb18-227" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-228"><a href="#cb18-228" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-229"><a href="#cb18-229" aria-hidden="true" tabindex="-1"></a><span class="fu">## Casualties</span></span>
<span id="cb18-232"><a href="#cb18-232" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-233"><a href="#cb18-233" aria-hidden="true" tabindex="-1"></a>dates <span class="ot">&lt;-</span> approval <span class="sc">%&gt;%</span></span>
<span id="cb18-234"><a href="#cb18-234" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month)</span>
<span id="cb18-235"><a href="#cb18-235" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-236"><a href="#cb18-236" aria-hidden="true" tabindex="-1"></a>casualties_oef <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OEFMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-237"><a href="#cb18-237" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"oef"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-238"><a href="#cb18-238" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-239"><a href="#cb18-239" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb18-240"><a href="#cb18-240" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-241"><a href="#cb18-241" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-242"><a href="#cb18-242" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb18-243"><a href="#cb18-243" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb18-244"><a href="#cb18-244" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-245"><a href="#cb18-245" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb18-246"><a href="#cb18-246" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-247"><a href="#cb18-247" aria-hidden="true" tabindex="-1"></a>casualties_ofs <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OFSMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-248"><a href="#cb18-248" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"ofs"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-249"><a href="#cb18-249" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-250"><a href="#cb18-250" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb18-251"><a href="#cb18-251" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-252"><a href="#cb18-252" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-253"><a href="#cb18-253" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb18-254"><a href="#cb18-254" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb18-255"><a href="#cb18-255" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-256"><a href="#cb18-256" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb18-257"><a href="#cb18-257" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-258"><a href="#cb18-258" aria-hidden="true" tabindex="-1"></a>casualties_oif <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OIFMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-259"><a href="#cb18-259" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"oif"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-260"><a href="#cb18-260" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-261"><a href="#cb18-261" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb18-262"><a href="#cb18-262" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-263"><a href="#cb18-263" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-264"><a href="#cb18-264" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb18-265"><a href="#cb18-265" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb18-266"><a href="#cb18-266" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-267"><a href="#cb18-267" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb18-268"><a href="#cb18-268" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-269"><a href="#cb18-269" aria-hidden="true" tabindex="-1"></a>casualties_oir <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>, <span class="st">"OIRMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-270"><a href="#cb18-270" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"oir"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-271"><a href="#cb18-271" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-272"><a href="#cb18-272" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb18-273"><a href="#cb18-273" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-274"><a href="#cb18-274" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-275"><a href="#cb18-275" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb18-276"><a href="#cb18-276" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb18-277"><a href="#cb18-277" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-278"><a href="#cb18-278" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb18-279"><a href="#cb18-279" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-280"><a href="#cb18-280" aria-hidden="true" tabindex="-1"></a>casualties_ond <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_xls</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>,<span class="st">"ONDMonthly.xls"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-281"><a href="#cb18-281" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"ond"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-282"><a href="#cb18-282" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">date =</span> <span class="st">"Month/Year"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-283"><a href="#cb18-283" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="st">"date"</span> <span class="ot">=</span> stringr<span class="sc">::</span><span class="fu">str_squish</span>(date)) <span class="sc">%&gt;%</span></span>
<span id="cb18-284"><a href="#cb18-284" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> date, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">" "</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-285"><a href="#cb18-285" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_to_title</span>(month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-286"><a href="#cb18-286" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> <span class="fu">match</span>(month, month.name)) <span class="sc">%&gt;%</span></span>
<span id="cb18-287"><a href="#cb18-287" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">month =</span> stringr<span class="sc">::</span><span class="fu">str_pad</span>(month, <span class="dv">2</span>, <span class="at">pad =</span> <span class="st">"0"</span>),</span>
<span id="cb18-288"><a href="#cb18-288" aria-hidden="true" tabindex="-1"></a>                <span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-289"><a href="#cb18-289" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month, conflict, TOTL_hostile, TOTL_all)</span>
<span id="cb18-290"><a href="#cb18-290" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-291"><a href="#cb18-291" aria-hidden="true" tabindex="-1"></a>casualties_aad <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/inst/extdata/casualties/"</span>,<span class="st">"aad-search-results.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-292"><a href="#cb18-292" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(INCIDENT.OR.DEATH.DATE,</span>
<span id="cb18-293"><a href="#cb18-293" aria-hidden="true" tabindex="-1"></a>                HOSTILE.OR.NON.HOSTILE.DEATH.INDICATOR) <span class="sc">%&gt;%</span></span>
<span id="cb18-294"><a href="#cb18-294" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">separate</span>(<span class="at">col =</span> INCIDENT.OR.DEATH.DATE, <span class="at">into =</span> <span class="fu">c</span>(<span class="st">"month"</span>, <span class="st">"day"</span>, <span class="st">"year"</span>), <span class="at">sep =</span> <span class="st">"/"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-295"><a href="#cb18-295" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">start_date_month =</span> <span class="fu">paste0</span>(year, <span class="st">"-"</span>, month)) <span class="sc">%&gt;%</span></span>
<span id="cb18-296"><a href="#cb18-296" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(start_date_month, HOSTILE.OR.NON.HOSTILE.DEATH.INDICATOR) <span class="sc">%&gt;%</span></span>
<span id="cb18-297"><a href="#cb18-297" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">count =</span> <span class="fu">n</span>()) <span class="sc">%&gt;%</span></span>
<span id="cb18-298"><a href="#cb18-298" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb18-299"><a href="#cb18-299" aria-hidden="true" tabindex="-1"></a>  tidyr<span class="sc">::</span><span class="fu">pivot_wider</span>(<span class="at">id_cols =</span> start_date_month,</span>
<span id="cb18-300"><a href="#cb18-300" aria-hidden="true" tabindex="-1"></a>                     <span class="at">names_from =</span> HOSTILE.OR.NON.HOSTILE.DEATH.INDICATOR,</span>
<span id="cb18-301"><a href="#cb18-301" aria-hidden="true" tabindex="-1"></a>                     <span class="at">values_from =</span> count) <span class="sc">%&gt;%</span></span>
<span id="cb18-302"><a href="#cb18-302" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">rename</span>(<span class="at">TOTL_hostile =</span> <span class="st">'Hostile Death'</span>, <span class="at">TOTL_nonhostile =</span> <span class="st">'Non-Hostile Death'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-303"><a href="#cb18-303" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_hostile =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_hostile, <span class="dv">0</span>),</span>
<span id="cb18-304"><a href="#cb18-304" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_nonhostile =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_nonhostile, <span class="dv">0</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-305"><a href="#cb18-305" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_all =</span> <span class="fu">as.numeric</span>(TOTL_hostile) <span class="sc">+</span> <span class="fu">as.numeric</span>(TOTL_nonhostile)) <span class="sc">%&gt;%</span></span>
<span id="cb18-306"><a href="#cb18-306" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(<span class="sc">-</span>TOTL_nonhostile) <span class="sc">%&gt;%</span></span>
<span id="cb18-307"><a href="#cb18-307" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">conflict =</span> <span class="st">"aad"</span>)</span>
<span id="cb18-308"><a href="#cb18-308" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-309"><a href="#cb18-309" aria-hidden="true" tabindex="-1"></a>casualties_all <span class="ot">&lt;-</span> <span class="fu">rbind</span>(casualties_aad,</span>
<span id="cb18-310"><a href="#cb18-310" aria-hidden="true" tabindex="-1"></a>                        casualties_oef,</span>
<span id="cb18-311"><a href="#cb18-311" aria-hidden="true" tabindex="-1"></a>                        casualties_ofs,</span>
<span id="cb18-312"><a href="#cb18-312" aria-hidden="true" tabindex="-1"></a>                        casualties_oif,</span>
<span id="cb18-313"><a href="#cb18-313" aria-hidden="true" tabindex="-1"></a>                        casualties_oir,</span>
<span id="cb18-314"><a href="#cb18-314" aria-hidden="true" tabindex="-1"></a>                        casualties_ond)</span>
<span id="cb18-315"><a href="#cb18-315" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-316"><a href="#cb18-316" aria-hidden="true" tabindex="-1"></a>casualties_all <span class="ot">&lt;-</span> casualties_all <span class="sc">%&gt;%</span></span>
<span id="cb18-317"><a href="#cb18-317" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">group_by</span>(start_date_month) <span class="sc">%&gt;%</span></span>
<span id="cb18-318"><a href="#cb18-318" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">TOTL_hostile_all =</span> <span class="fu">sum</span>(TOTL_hostile),</span>
<span id="cb18-319"><a href="#cb18-319" aria-hidden="true" tabindex="-1"></a>                   <span class="at">TOTL_all_all =</span> <span class="fu">sum</span>(TOTL_all))</span>
<span id="cb18-320"><a href="#cb18-320" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-321"><a href="#cb18-321" aria-hidden="true" tabindex="-1"></a>casualties_all <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(dates, casualties_all) <span class="sc">%&gt;%</span></span>
<span id="cb18-322"><a href="#cb18-322" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_hostile =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_hostile_all, <span class="dv">0</span>),</span>
<span id="cb18-323"><a href="#cb18-323" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_all =</span> dplyr<span class="sc">::</span><span class="fu">coalesce</span>(TOTL_all_all, <span class="dv">0</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-324"><a href="#cb18-324" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(start_date_month,</span>
<span id="cb18-325"><a href="#cb18-325" aria-hidden="true" tabindex="-1"></a>                TOTL_hostile, TOTL_all) <span class="sc">%&gt;%</span></span>
<span id="cb18-326"><a href="#cb18-326" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">TOTL_hostileL1 =</span> <span class="fu">lag</span>(TOTL_hostile),</span>
<span id="cb18-327"><a href="#cb18-327" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_allL1 =</span> <span class="fu">lag</span>(TOTL_all),</span>
<span id="cb18-328"><a href="#cb18-328" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_hostileL2 =</span> <span class="fu">lag</span>(TOTL_hostileL1),</span>
<span id="cb18-329"><a href="#cb18-329" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_allL2 =</span> <span class="fu">lag</span>(TOTL_allL1),</span>
<span id="cb18-330"><a href="#cb18-330" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_hostile_chg =</span> TOTL_hostileL2 <span class="sc">-</span> TOTL_hostileL1,</span>
<span id="cb18-331"><a href="#cb18-331" aria-hidden="true" tabindex="-1"></a>                <span class="at">TOTL_all_chg =</span> TOTL_allL2 <span class="sc">-</span> TOTL_allL1)</span>
<span id="cb18-332"><a href="#cb18-332" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-333"><a href="#cb18-333" aria-hidden="true" tabindex="-1"></a><span class="co"># Merge</span></span>
<span id="cb18-334"><a href="#cb18-334" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, casualties_all)</span>
<span id="cb18-335"><a href="#cb18-335" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-336"><a href="#cb18-336" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-337"><a href="#cb18-337" aria-hidden="true" tabindex="-1"></a><span class="fu">## Collateral damage</span></span>
<span id="cb18-338"><a href="#cb18-338" aria-hidden="true" tabindex="-1"></a>Urban areas mean low tech</span>
<span id="cb18-341"><a href="#cb18-341" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-342"><a href="#cb18-342" aria-hidden="true" tabindex="-1"></a>gis <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/aux/"</span>,<span class="st">"coordinates.csv"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb18-343"><a href="#cb18-343" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">select</span>(wikidata_id, urban, forested, mountainous) <span class="sc">%&gt;%</span></span>
<span id="cb18-344"><a href="#cb18-344" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">urban_binary =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(urban <span class="sc">==</span> <span class="dv">2</span>, <span class="dv">1</span>, <span class="dv">0</span>))</span>
<span id="cb18-345"><a href="#cb18-345" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-346"><a href="#cb18-346" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> dplyr<span class="sc">::</span><span class="fu">left_join</span>(df_interv, gis)</span>
<span id="cb18-347"><a href="#cb18-347" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-348"><a href="#cb18-348" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-349"><a href="#cb18-349" aria-hidden="true" tabindex="-1"></a><span class="fu"># Final clean</span></span>
<span id="cb18-350"><a href="#cb18-350" aria-hidden="true" tabindex="-1"></a>Fix variable types</span>
<span id="cb18-353"><a href="#cb18-353" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-354"><a href="#cb18-354" aria-hidden="true" tabindex="-1"></a><span class="fu">str</span>(df_interv)</span>
<span id="cb18-355"><a href="#cb18-355" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-356"><a href="#cb18-356" aria-hidden="true" tabindex="-1"></a>df_interv <span class="ot">&lt;-</span> df_interv <span class="sc">%&gt;%</span></span>
<span id="cb18-357"><a href="#cb18-357" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">mutate_at</span>(<span class="fu">c</span>(<span class="st">"wikidata_id"</span>,</span>
<span id="cb18-358"><a href="#cb18-358" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"parent_id"</span>,</span>
<span id="cb18-359"><a href="#cb18-359" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"multilateral1"</span>,</span>
<span id="cb18-360"><a href="#cb18-360" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_statenonstate_ordinal"</span>,</span>
<span id="cb18-361"><a href="#cb18-361" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_state_binary"</span>,</span>
<span id="cb18-362"><a href="#cb18-362" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_nonstate_all_binary"</span>,</span>
<span id="cb18-363"><a href="#cb18-363" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_nonstate_major_binary"</span>,</span>
<span id="cb18-364"><a href="#cb18-364" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"sideB_nonstate_minor_binary"</span>,</span>
<span id="cb18-365"><a href="#cb18-365" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"demparty"</span>,</span>
<span id="cb18-366"><a href="#cb18-366" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"urban"</span>,</span>
<span id="cb18-367"><a href="#cb18-367" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"urban_binary"</span>,</span>
<span id="cb18-368"><a href="#cb18-368" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"forested"</span>,</span>
<span id="cb18-369"><a href="#cb18-369" aria-hidden="true" tabindex="-1"></a>                     <span class="st">"mountainous"</span>), factor) <span class="sc">%&gt;%</span></span>
<span id="cb18-370"><a href="#cb18-370" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">distinct</span>()</span>
<span id="cb18-371"><a href="#cb18-371" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb18-372"><a href="#cb18-372" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-373"><a href="#cb18-373" aria-hidden="true" tabindex="-1"></a><span class="fu"># Save</span></span>
<span id="cb18-376"><a href="#cb18-376" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb18-377"><a href="#cb18-377" aria-hidden="true" tabindex="-1"></a><span class="fu">write.csv</span>(df_interv, <span class="fu">paste0</span>(here<span class="sc">::</span><span class="fu">here</span>(), <span class="st">"/data/"</span>,<span class="st">"MONSTr.csv"</span>))</span>
<span id="cb18-378"><a href="#cb18-378" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
</code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div></div></div></div></div>
</div> <!-- /content -->



</body></html>